zoukankan      html  css  js  c++  java
  • 二维数组中的查找

    题目描述

    在一个二维数组中,每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序。请完成一个函数,输入这样的一个二维数组和一个整数,判断数组中是否含有该整数。
     1 class Solution {
     2 public:
     3     bool Find(vector<vector<int> > array,int target) {
     4          bool found=false;
     5          int rows=array.size();
     6         int columns=array[0].size();
     7         if(rows>0&&columns>0)
     8             {
     9             
    10          int row=0;
    11       int column=columns-1;
    12     while(row<rows&&column>=0)
    13     {
    14         if(array[row][column]==target)
    15         {
    16            return true;
    17         }
    18         else if(array[row][column]>target)
    19         {
    20             column--;
    21         }
    22         else
    23            row++;
    24     }
    25     return false;
    26         }
    27   }   
    28 };
  • 相关阅读:
    59
    58
    57
    56
    55
    54
    53
    转 Using $.ajaxPrefilter() To Configure AJAX Requests In jQuery 1.5
    jquery用正则表达式验证密码强度
    什么是高内聚、低耦合?(转载)
  • 原文地址:https://www.cnblogs.com/cancangood/p/4924348.html
Copyright © 2011-2022 走看看