您的位置:首页 > 其它

LeetCode || Search a 2D Matrix II

2015-09-05 11:15 363 查看
class Solution {
public:
bool searchMatrix(vector<vector<int>>& matrix, int target) {
int row = matrix.size();
if(row == 0)
return false;
int col = matrix[0].size();
if(col == 0)
return false;

int i = 0;
int j = col -1;

while( i < row && j >= 0)
{
if(matrix[i][j] == target)
return true;
if(matrix[i][j] > target)
{
j--;
}
else
i++;
}

return false;
}
};
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: