diff --git a/solution/0073.Set Matrix Zeroes/Solution.py b/solution/0073.Set Matrix Zeroes/Solution.py new file mode 100644 index 0000000000000..d432b8aeb7bb2 --- /dev/null +++ b/solution/0073.Set Matrix Zeroes/Solution.py @@ -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 diff --git a/solution/0074.Search a 2D Matrix/Solution.py b/solution/0074.Search a 2D Matrix/Solution.py new file mode 100644 index 0000000000000..d17ec1f8d51fa --- /dev/null +++ b/solution/0074.Search a 2D Matrix/Solution.py @@ -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