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