Skip to content

Commit 13bda6b

Browse files
authored
Create leftmost-column-with-at-least-a-one.py
1 parent 2ee0889 commit 13bda6b

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Time: O(m + n)
2+
# Space: O(1)
3+
4+
class BinaryMatrix(object):
5+
def get(self, row, col):
6+
pass
7+
8+
def dimensions(self):
9+
pass
10+
11+
12+
class Solution(object):
13+
def leftMostColumnWithOne(self, binaryMatrix):
14+
"""
15+
:type binaryMatrix: BinaryMatrix
16+
:rtype: int
17+
"""
18+
m, n = binaryMatrix.dimensions()
19+
r, c = 0, n-1
20+
while r < m and c >= 0:
21+
if not binaryMatrix.get(r, c):
22+
r += 1
23+
else:
24+
c -= 1
25+
return c+1 if c+1 != n else -1

0 commit comments

Comments
 (0)