Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added merge-sorted-array.cpp
Empty file.
Empty file added remove-duplicates.cpp
Empty file.
19 changes: 19 additions & 0 deletions search-2d-matrix.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class Solution {
public:
bool searchMatrix(vector<vector<int>>& matrix, int target) {
int m = matrix.size();
int n = matrix[0].size();
int i = 0;
int j = n - 1;
while(i < m && j >=0){
if(matrix[i][j] == target)return true;
else if(matrix[i][j] > target){
j--;//move towards the smaller elements
}else{
i++;//move towards the larger elements
}
}

return false;//element not found
}
};