码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2016-01-07 18:16:51      阅读:140      评论:0      收藏:0      [点我收藏+]

标签:

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 };

 

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

标签:

原文地址:http://www.cnblogs.com/CheeseZH/p/5110536.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!