Created
June 9, 2020 04:47
-
-
Save misterpoloy/d25155b8f9da1a591ff1aec936a1fcc7 to your computer and use it in GitHub Desktop.
#CodeChallenge Search in sorted matrix use of column index and row index.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <vector> | |
using namespace std; | |
vector<int> searchInSortedMatrix(vector<vector<int>> matrix, int target) { | |
int col = matrix[0].size() - 1; | |
int row = 0; | |
while (row < matrix.size() && col >= 0) { | |
if (target < matrix[row][col]) { | |
col--; | |
} else if (target > matrix[row][col]) { | |
row++; | |
} else { | |
return { row, col }; | |
} | |
} | |
return { -1, -1 }; | |
} |
Author
misterpoloy
commented
Jun 9, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment