LeetCode 74. Search a 2D Matrix
LeetCode 74. Search a 2D Matrix ๐๏ธ Daily LeetCoding Challenge August, Day 7 Simple Search Think from-simple-to-complex! First, I just simply search over the matrix and check if target value is in each line. Fortunately, this code didnโt trigger TLE. class Solution: def searchMatrix(self, matrix: List[List[int]], target: int) -> bool: for i in range(len(matrix)): if matrix[i][-1] >= target: if target in matrix[i]: return True else: return False Binary Search However in order to improve runtime, itโs better to use binary search than just checking with in. Similar to the previous simple search code. ...