상위 150개 인터뷰쉬움

2D 매트릭스 검색

'2D 매트릭스 검색' 문제에 대한 자세한 가이드 및 Python 구현입니다.

문제 설명

쉬움

다음 두 가지 속성을 가진 m x n 정수 행렬 matrix이 제공됩니다.

- 각 행은 내림차순으로 정렬됩니다.

- 각 행의 첫 번째 정수는 이전 행의 마지막 정수보다 큽니다.

정수 target가 주어지면 targetmatrix에 있으면 True을 반환하고 그렇지 않으면 False을 반환합니다.

O(log(m * n)) 시간 복잡도로 솔루션을 작성해야 합니다.

searchMatrix(matrix: List[List[int]], target: int) -> bool 함수를 작성하세요.

제약
  • m == len(matrix)
  • n == len(matrix[i])
  • 1 <= m, n <= 100
  • -10^4 <= matrix[i][j], target <= 10^4

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

3 is found in the first row at index 1.

Example 2
Input
matrix = [[1, 3, 5, 7], [10, 11, 16, 20], [23, 30, 34, 60]], target = 13
Output
False
Explanation

13 is not present in the matrix.

Need a Hint?
세트나 힙과 같은 이진 검색 관련 데이터 구조를 사용하는 것을 고려해보세요.
Edge Cases to Watch
  • 빈 입력 구조
  • 단일 요소 입력
  • 큰 수치 범위

해결할 준비가 되셨나요?

Open the problem in PyRun's browser-based Python editor. Your code runs fully offline — no server required.

편집기에서 열기
Found this breakdown helpful?

PyRun is built and maintained by an independent solo developer. If this helped your interview prep, consider buying a coffee!

Buy me a coffee

권장 Python 리소스

관련 대화형 튜토리얼, 치트 시트, 코드 비교를 통해 지식을 확장하세요.