class Solution(object):
def searchMatrix(self, matrix, target):
"""
:type matrix: List[List[int]]
:type target: int
:rtype: bool
"""
if len(matrix)==0 or len(matrix[0])==0:
return False
h,w=len(matrix),len(matrix[0])
left=0
right=h-1
while left<=right:
ind = (left+right)/2
print left, right, ind
if target==matrix[ind][0]:
break
elif target<matrix[ind][0]:
right=ind-1
else:
left=ind+1
ind = (left+right)/2
if ind<0:
return False
left=0
right=w-1
while left<=right:
x = (left+right)/2
if target==matrix[ind][x]:
return True
elif target<matrix[ind][x]:
right=x-1
else:
left=x+1
return False