Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions solution/0073.Set Matrix Zeroes/Solution.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class Solution:
def setZeroes(self, matrix):
"""
:type matrix: List[List[int]]
:rtype: void Do not return anything, modify matrix in-place instead.
"""

coord = []
for i in range(len(matrix)):
for j in range(len(matrix[i])):
if matrix[i][j] == 0:
coord.append((i, j))

for i, j in coord:
matrix[i] = [0]*len(matrix[i])
for x in range(len(matrix)):
matrix[x][j] = 0
27 changes: 27 additions & 0 deletions solution/0074.Search a 2D Matrix/Solution.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
class Solution:
def searchMatrix(self, matrix, target):
"""
:type matrix: List[List[int]]
:type target: int
:rtype: bool
"""

if not matrix or not matrix[0]:
return False

for row in matrix:
if row[0] <= target <= row[-1]:
s = 0
e = len(row)-1
while s <= e:
mid = (s+e)//2
if row[mid] == target:
return True
elif row[mid] > target:
e = mid-1
else:
s = mid+1

return False

return False