일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 | 31 |
Tags
- 315. Count of Smaller Numbers After Self
- DWG
- 밴픽
- 컴퓨터의 구조
- 109. Convert Sorted List to Binary Search Tree
- LeetCode
- iterator
- 프로그래머스
- concurrency
- Class
- 43. Multiply Strings
- 715. Range Module
- 운영체제
- Regular Expression
- attribute
- t1
- kaggle
- Python Code
- shiba
- Python Implementation
- Decorator
- 파이썬
- 시바견
- Generator
- Substring with Concatenation of All Words
- 30. Substring with Concatenation of All Words
- data science
- Protocol
- Convert Sorted List to Binary Search Tree
- Python
Archives
- Today
- Total
Scribbling
LeetCode: 74. Search a 2D Matrix 본문
class Solution:
def searchMatrix(self, matrix: List[List[int]], target: int) -> bool:
if target < matrix[0][0] or target > matrix[-1][-1]:
return False
m, n = len(matrix), len(matrix[0])
row = 0
# row search
l, r = 0, m - 1
while l <= r:
mid = (l + r) // 2
if matrix[mid][0] > target:
r = mid - 1
else:
row = max(row, mid)
l = mid + 1
# column search
l, r = 0, n - 1
while l <= r:
mid = (l + r) // 2
if matrix[row][mid] == target:
return True
if matrix[row][mid] < target:
l = mid + 1
else:
r = mid - 1
return False
'Computer Science > Coding Test' 카테고리의 다른 글
LeetCode: 77. Combinations (0) | 2021.09.28 |
---|---|
LeetCode: 75. Sort Colors (0) | 2021.09.28 |
LeetCode: 73. Set Matrix Zeroes (0) | 2021.09.28 |
LeetCode: 72. Edit Distance (0) | 2021.09.26 |
LeetCode: 71. Simplify Path (0) | 2021.09.26 |