# Leetcode 74. Search 2D matrix ## 逐行二分查找 ```python= class Solution: def searchMatrix(self, matrix: List[List[int]], target: int) -> bool: xc, yc = len(matrix[0]), len(matrix) def binarySearch(nums: List[int], target: int, length: int): left = 0 right = length - 1 while left <= right: mid = left + (right - left) // 2 if nums[mid] < target: left = mid + 1 elif nums[mid] > target: right = mid - 1 else: return True return False for y in range(yc): if binarySearch(matrix[y],target, xc): return True return False ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up