-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathSolution.cpp
More file actions
35 lines (31 loc) · 741 Bytes
/
Solution.cpp
File metadata and controls
35 lines (31 loc) · 741 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
#include <string>
#include <vector>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <tuple>
#include <deque>
#include <unordered_map>
#include <cmath>
#include <queue>
using namespace std;
class Solution {
public:
bool searchMatrix(vector<vector<int>>& matrix, int target) {
int x = matrix.size();
if (x < 1) return false;
int y = matrix[0].size();
if (y < 1) return false;
int i = x - 1, j = 0;
while (i >= 0 and j < y) {
if (matrix[i][j] == target) return true;
else if (matrix[i][j] < target) j ++ ;
else if (matrix[i][j] > target) i -- ;
}
return false;
}
};
int main() {
Solution a;
return 0;
}