-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path74.cpp
More file actions
34 lines (30 loc) · 864 Bytes
/
74.cpp
File metadata and controls
34 lines (30 loc) · 864 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
// Problem : 74. Search a 2D Matrix
// Link : https://leetcode.com/problems/search-a-2d-matrix/
#include <iostream>
#include <vector>
#include <bits/stdc++.h>
using namespace std;
class Solution {
public:
bool searchMatrix(vector<vector<int>>& matrix, int target) {
int row_size = matrix[0].size();
for(int i = 0; i < matrix.size(); i++){
if(target <= matrix[i][row_size - 1]){
if(target < matrix[i][0])
return false;
if (binary_search(matrix[i].begin(), matrix[i].end(), target))
return true;
else
return false;
}
}
return false;
}
};
int main() {
Solution ob;
vector<vector<int>> matrix = {{1,1}};
int target = 2;
cout << ob.searchMatrix(matrix, target);
return 0;
}