<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      Search a 2D Matrix

      Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:

      • Integers in each row are sorted from left to right.
      • The first integer of each row is greater than the last integer of the previous row.

      For example,

      Consider the following matrix:

      [
        [1,   3,  5,  7],
        [10, 11, 16, 20],
        [23, 30, 34, 50]
      ]
      

      Given target = 3, return true.

      public class Solution {
          public boolean searchMatrix(int[][] matrix, int target) {
              int m = matrix.length;
              if(m==0)
                  return false;
              int n=matrix[0].length;
              if(matrix[m-1][n-1]<target||matrix[0][0]>target)
                  return false;
                  
              int first=0;
              int last=m-1;
              //二分法,判斷target所在的行
              //判斷條件不能使<=,防止m==1時,while是死循環
              while(first<last){
                  int center=(first+last)/2;
                  if(matrix[center][n-1]<target){
                      first=center+1;
                  }else if(matrix[center][n-1]==target){
                      return true;
                  }
                  else{
                      last=center;
                  }
              }
              
              int left=0;
              int right=n-1;
              //二分法,判斷target所屬的列
              while(left<=right){
                  int center=(left+right)/2;
                  if(matrix[first][center]==target)
                      return true;
                  else if(matrix[first][center]<target){
                      left=center+1;
                      
                  }else{
                      right=center-1;
                  }
              }
              return false;
          }
      }





      posted @ 2014-12-17 18:51  bingtel  閱讀(159)  評論(0)    收藏  舉報
      主站蜘蛛池模板: 91精品国产自产在线蜜臀| 国产喷水1区2区3区咪咪爱AV| 国产欧美日韩视频怡春院| 贵溪市| 国产视频最新| 久久国产精品老人性| 日本亚洲一区二区精品| 免费观看日本污污ww网站69| 欧洲精品色在线观看| 精品人妻蜜臀一区二区三区| 深夜av在线免费观看| 福利视频在线播放| 亚洲精品无码久久久影院相关影片| 久久99精品久久久大学生| free性开放小少妇| 97视频精品全国免费观看 | 亚洲精品二区在线播放| 日韩精品国产另类专区| 日本一区二区三深夜不卡| 中文字幕日韩精品有码| 在线看国产精品自拍内射| 深田えいみ禁欲后被隔壁人妻| 被灌满精子的少妇视频| 精品国产乱码久久久久APP下载| 精品国产综合成人亚洲区| 粗壮挺进邻居人妻无码| 本道久久综合无码中文字幕| 99久久精品久久久久久婷婷| av一本久道久久综合久久鬼色| 国产成人啪精品午夜网站| 大地资源网第二页免费观看| 在线精品自拍亚洲第一区| 成人自拍小视频免费观看| 丰满人妻被黑人连续中出| 亚洲精品成人片在线播放| 天堂一区二区三区av| 少妇人妻偷人精品无码视频| 国产91精品调教在线播放| 久久香蕉国产线看观看猫咪av | 中文字幕无码av不卡一区| 狠狠综合久久av一区二|