We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 2ee0889 commit 13bda6bCopy full SHA for 13bda6b
Python/leftmost-column-with-at-least-a-one.py
@@ -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
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