Skip to content

Commit 726de4a

Browse files
committed
Solution as on 25-03-2022 07:47 pm
1 parent 0226f35 commit 726de4a

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

0240. Search a 2D Matrix II.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// 240.✅ Search a 2D Matrix II
2+
3+
class Solution {
4+
public:
5+
bool searchMatrix(vector<vector<int>>& matrix, int target) {
6+
int r = matrix.size();
7+
int c = matrix[0].size();
8+
9+
int i = 0, j = c-1;
10+
11+
while(i < r && j >= 0)
12+
{
13+
if(matrix[i][j] == target )
14+
return true;
15+
else if(matrix[i][j] > target)
16+
--j;
17+
else
18+
++i;
19+
}
20+
21+
return false;
22+
}
23+
};

0 commit comments

Comments
 (0)