-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday21.py
38 lines (32 loc) · 900 Bytes
/
day21.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
36
37
38
"""
This is BinaryMatrix's API interface.
You should not implement it, or speculate about its implementation
"""
class BinaryMatrix(object):
def get(self, x, y):
"""
:type x : int, y : int
:rtype int
"""
def dimensions():
"""
:rtype list[]
"""
def leftMostColumnWithOne(self, binaryMatrix):
"""
:type binaryMatrix: BinaryMatrix
:rtype: int
"""
rows,cols = binaryMatrix.dimensions()
current_row = 0
current_col = cols-1
while current_row < rows and current_col>=0:
if binaryMatrix.get(current_row,current_col)==0:
current_row+=1
else:
current_col-=1
if current_col != cols-1:
return current_col+1
else:
return -1
print(BinaryMatrix.leftMostColumnWithOne([[0,0],[1,1]]))