일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- attribute
- Python Implementation
- 30. Substring with Concatenation of All Words
- Python Code
- 프로그래머스
- Python
- 운영체제
- Protocol
- kaggle
- LeetCode
- t1
- 315. Count of Smaller Numbers After Self
- 시바견
- data science
- Substring with Concatenation of All Words
- 파이썬
- Regular Expression
- Class
- Convert Sorted List to Binary Search Tree
- iterator
- 컴퓨터의 구조
- Decorator
- 43. Multiply Strings
- DWG
- 715. Range Module
- concurrency
- Generator
- 109. Convert Sorted List to Binary Search Tree
- 밴픽
- shiba
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 |