Leetcode 74

Posted 村雨sup

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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;
    }
};

 

以上是关于Leetcode 74的主要内容,如果未能解决你的问题,请参考以下文章

leetcode-通配符匹配(动态规划)-74

p74 阶乘末尾0的个数(leetcode 172)

LeetCode74. 搜索二维矩阵

LeetCode Solution-74

[JavaScript 刷题] 二分搜索 - 搜索二维矩阵, leetcode 74

[JavaScript 刷题] 二分搜索 - 搜索二维矩阵, leetcode 74