leetcode74Search a 2D Matrix
来源:互联网 发布:2016餐饮软件排名 编辑:程序博客网 时间:2024/06/10 09:40
class Solution(object):
def searchMatrix(self, matrix, target):
"""
:type matrix: List[List[int]]
:type target: int
:rtype: bool
"""
if not matrix:
return False
n=len(matrix)
m=len(matrix[0])
l,r=0,n*m-1
while l<=r:
mid=l+(r-l)/2
e=matrix[mid/m][mid%m]
if e==target:
return True
elif e<target:
l=mid+1
else:
r=mid-1
return False
def searchMatrix(self, matrix, target):
"""
:type matrix: List[List[int]]
:type target: int
:rtype: bool
"""
if not matrix:
return False
n=len(matrix)
m=len(matrix[0])
l,r=0,n*m-1
while l<=r:
mid=l+(r-l)/2
e=matrix[mid/m][mid%m]
if e==target:
return True
elif e<target:
l=mid+1
else:
r=mid-1
return False
0 0
- leetcode74Search a 2D Matrix
- Search a 2D Matrix
- Search a 2D Matrix
- Search a 2D Matrix
- Search a 2D Matrix
- Search a 2D Matrix
- Search a 2D Matrix
- Search a 2D Matrix
- Search a 2D Matrix
- Search a 2D Matrix
- Search a 2D Matrix
- Search a 2D Matrix
- Search a 2D Matrix
- Search a 2D Matrix
- Search a 2D Matrix
- Search a 2D Matrix
- Search a 2D Matrix
- Search a 2D matrix
- 图像处理工程师笔试题
- Python-运算符
- memset的使用注意
- css样式表基本属性1
- 如何查看内核版本和ubuntu版本
- leetcode74Search a 2D Matrix
- YII框架的行为
- Java的 类名.this
- UVA
- Unity3D学习(13)之UI界面与背包系统
- 4.5版本eclipse安装activiti插件
- STM32——小车2个直流电机运动控制
- Problem K: STL——水果店
- Docker之常用命令