码迷,mamicode.com
首页 > 其他好文 > 详细

剑指Offer_编程题_1

时间:2018-04-22 13:00:40      阅读:196      评论:0      收藏:0      [点我收藏+]

标签:solution   size   顺序   tor   turn   cto   二维   描述   als   

题目描述

在一个二维数组中,每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序。请完成一个函数,输入这样的一个二维数组和一个整数,判断数组中是否含有该整数。
 
class Solution {
public:
    bool Find(int target, vector<vector<int> > array) {
        int row = array.size();
        int low = array[0].size();
        int i=row-1,j=0;
        while(i>=0 && j<low) {
            if(array[i][j] == target) {
                return true;
            } else if(array[i][j] > target) {
                i--;
            } else {
                j++;
            }
        }
        return false;
    }
};

  

 

剑指Offer_编程题_1

标签:solution   size   顺序   tor   turn   cto   二维   描述   als   

原文地址:https://www.cnblogs.com/grglym/p/8906031.html

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