Skip to content

Commit 835d35e

Browse files
committed
Time: 95 ms (82.71%), Space: 17.8 MB (9.82%) - LeetHub
1 parent 6558163 commit 835d35e

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# time complexity: O(n * m)
2+
# space complexity: O(1)
3+
# class BinaryMatrix(object):
4+
# def get(self, row: int, col: int) -> int:
5+
# def dimensions(self) -> list[int]:
6+
7+
import bisect
8+
9+
10+
class Row:
11+
def __init__(self, row, matrix):
12+
self.id = row
13+
self.matrix = matrix
14+
15+
def __getitem__(self, j):
16+
return self.matrix.get(self.id, j)
17+
18+
def __len__(self):
19+
return self.matrix.dimensions()[1]
20+
21+
22+
class Solution:
23+
def leftMostColumnWithOne(self, binaryMatrix: 'BinaryMatrix') -> int:
24+
n, m = binaryMatrix.dimensions()
25+
26+
s = bisect.bisect_left(Row(0, binaryMatrix), 1)
27+
for i in range(1, n):
28+
s = min(s, bisect.bisect_left(Row(i, binaryMatrix), 1))
29+
30+
if s == m:
31+
return -1
32+
return s

0 commit comments

Comments
 (0)