zoukankan      html  css  js  c++  java
  • Leetcode 74

    class Solution {
    public:
        bool searchMatrix(vector<vector<int>>& matrix, int target) {
            int m = matrix.size();
            if(!m) return false;
            int n = matrix[0].size();
            if(!n) return false;
            if(target < matrix[0][0] || target > matrix[m-1][n-1]) return false;
            int a = m-1;
            for(int i=1;i < m;i++){
                if(target < matrix[i][0]){
                    a = i-1;
                    break;
                }
            }
            int j = 0;
            int k = n-1;
            while(j <= k){
                int mid = (j+k)/2;
                if(matrix[a][mid] < target){j = mid+1;}
                else if(matrix[a][mid] > target){k = mid - 1;}
                else{
                    return true;
                }
            }
            return false;
        }
    };
  • 相关阅读:
    Arr
    class4
    class3联大网页
    class33
    class3
    人机交换 NO 1书签
    大数据的框架与特点
    mapreduce排序
    mapreduce求平均数
    mapreduce去重
  • 原文地址:https://www.cnblogs.com/cunyusup/p/9863923.html
Copyright © 2011-2022 走看看