您的位置:首页 > Web前端

牛客网-《剑指offer》-二维数组中的查找

2016-01-07 17:13 369 查看
题目:http://www.nowcoder.com/practice/abc3fe2ce8e146608e868a70efebf62e

C++

class Solution {
public:
bool Find(vector<vector<int> > array,int target) {
int rows = array.size();
int cols = array[0].size();
int x = cols - 1;
int y = 0;
while ( x >= 0 && y < rows ) {
if (array[x][y] == target) return true;
if (array[x][y] < target) y++;
if (array[x][y] > target) x--;
}
return false;
}
};
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: