-
[💕 LeetCode Python] 240. Search a 2D Matrix 2Algorithm/1일 1코테 2020. 10. 26. 20:10반응형
✍
240.
Search a 2D Matrix 2
문제
leetcode.com/problems/search-a-2d-matrix-ii/submissions/
내가 쓴 답
def searchMatrix(self, matrix, target): for i in matrix: if target in i: return True return False
풀이
def searchMatrix(self, matrix, target): return any(target in row for row in matrix)
def searchMatrix(self, matrix, target): if not matrix: #matrix에 값이 없을 경우 return False #----------------------------- row = 0 col = len(matrix[0])-1 while row <= len(matrix)-1 and col >= 0: if target < matrix[row][col]: col -= 1 elif target > matrix[row][col]: row += 1 else: return True return False
반응형'Algorithm > 1일 1코테' 카테고리의 다른 글
[💕 LeetCode Python] 461. Hamming Distance (0) 2020.10.27 [💕 LeetCode Python] 136. Single Number (0) 2020.10.27 [🤷♀️ LeetCode Python] 167. Two Sum 2 - Input array is sorted (0) 2020.10.26 [💕 LeetCode Python] 349. Intersection of Two Arrays (0) 2020.10.26 [💕 LeetCode Python] 704. Binary Search (0) 2020.10.26