class Solution {
public:
bool searchMatrix(vector<vector<int> > &matrix, int target) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
int i = 0;
int j = matrix[0].size() - 1;
while (i < matrix.size() && j >= 0)
{
if (matrix[i][j] > target)
--j;
else if (matrix[i][j] < target)
++i;
else
return true;
}
return false;
}
};
[Leetcode] Search a 2D Matrix
最新推荐文章于 2020-05-02 19:57:48 发布