-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.cpp
More file actions
46 lines (38 loc) · 799 Bytes
/
main.cpp
File metadata and controls
46 lines (38 loc) · 799 Bytes
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
39
40
41
42
43
44
45
#include <iostream>
#include <vector>
class Point {
public:
int row;
int col;
Point(int r, int c) {
row = r;
col = c;
}
};
Point* findInMatrix(const std::vector<std::vector<int>>& matrix, int value) {
if (matrix.size() == 0) {
return nullptr;
}
if (matrix[0].size() == 0) {
return nullptr;
}
int row = 0;
int col = matrix.size() - 1;
while (row < matrix.size() && col >= 0) {
if (matrix[row][col] == 0) {
return new Point(row, col);
}
if (matrix[row][col] < value) {
row++;
continue;
}
if (matrix[row][col] > value) {
col--;
continue;
}
}
return NULL;
}
int main() {
return 0;
}