74. Search a 2D Matrix

Hill K·2022년 8월 17일
0

Algorithm

목록 보기
3/11

Example 1

Input: matrix = [[1,3,5,7],[10,11,16,20],[23,30,34,60]], target = 3
Output: true

Example 2

Input: matrix = [[1,3,5,7],[10,11,16,20],[23,30,34,60]], target = 13
Output: false

조건

m == matrix.length
n == matrix[i].length
1 <= m, n <= 100
-104 <= matrix[i][j], target <= 104

class Solution:
    def searchMatrix(self, matrix: List[List[int]], target: int) -> bool:
        for i in matrix:
            if target in i:
                return True
        
        return False

이진탐색 카테고리에 있기는 했지만 이게 더 빠른거같아서 이렇게 작성.

profile
안녕하세요

0개의 댓글