牛客网-《剑指offer》-二维数组中的查找
题目:http://www.nowcoder.com/practice/abc3fe2ce8e146608e868a70efebf62e
C++
1 class Solution { 2 public: 3 bool Find(vector<vector<int> > array,int target) { 4 int rows = array.size(); 5 int cols = array[0].size(); 6 int x = cols - 1; 7 int y = 0; 8 while ( x >= 0 && y < rows ) { 9 if (array[x][y] == target) return true; 10 if (array[x][y] < target) y++; 11 if (array[x][y] > target) x--; 12 } 13 return false; 14 } 15 };
找我内推: 字节跳动各种岗位
作者:
ZH奶酪(张贺)
邮箱:
cheesezh@qq.com
出处:
http://www.cnblogs.com/CheeseZH/
*
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。