-
Notifications
You must be signed in to change notification settings - Fork 3
/
1428.cpp
31 lines (28 loc) · 857 Bytes
/
1428.cpp
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
/**
* // This is the BinaryMatrix's API interface.
* // You should not implement it, or speculate about its implementation
* class BinaryMatrix {
* public:
* int get(int row, int col);
* vector<int> dimensions();
* };
*/
class Solution {
public:
int leftMostColumnWithOne(BinaryMatrix &binaryMatrix) {
vector<int> boundary = binaryMatrix.dimensions();
int res = INT_MAX;
for (int row = 0; row < boundary[0]; row++) {
int left = 0;
int right = boundary[1];
while (left < right) {
int mid = left + (right - left) / 2;
if (binaryMatrix.get(row, mid) >= 1) right = mid;
else left = mid + 1;
}
res = min(res, left);
}
if (res == boundary[1]) return -1;
return res;
}
};