-
Notifications
You must be signed in to change notification settings - Fork 0
/
74.py
38 lines (28 loc) · 857 Bytes
/
74.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/env python
# -*- coding: utf-8 -*-
__author__ = ['"wuyadong" <[email protected]>']
import bisect
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
start = 0
end = len(matrix)-1
while start <= end:
mid = (start+end)/2
if matrix[mid][0] > target:
end = mid-1
elif matrix[mid][-1] < target:
start = mid+1
else:
i = bisect.bisect_left(matrix[mid], target)
if matrix[mid][i] == target:
return True
else:
return False
return False