class Solution(object):
def searchMatrix(self, matrix, target):
"""
:type matrix: List[List[int]]
:type target: int
:rtype: bool
"""
m=len(matrix)
if m==0:
return False
n=len(matrix[0])
if n==0:
return False
i,j=m-1,0
while i>=0 and j<n:
if matrix[i][j]<target:
j+=1
elif matrix[i][j]>target:
i-=1
else:return True
return False
240. Search a 2D Matrix II
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
推荐阅读更多精彩内容
- Search a 2D Matrix II这个solution复杂度为O(row + column)主要思想是从右...
- 典型老题,从右上角开始搜索,往下是增往左是减。比如.[[1 4],[2 5]]右上角元素即4 ir是行标,ic是列...
- Write an efficient algorithm that searches for a value in...
- Write an efficient algorithm that searches for a value in...
- 240 Search a 2D Matrix II Total Accepted: 39652 Total Su...