首页 > 其他 > 详细

[二分搜索] leetcode 240 Search a 2D Matrix II

时间:2019-08-11 17:04:33      阅读:113      评论:0      收藏:0      [点我收藏+]

problem:https://leetcode.com/problems/search-a-2d-matrix-ii

         经典双指针二分查找题目。

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;
        
        int i = 0;
        int j = n - 1;
        while(i < m && j >= 0)
        {
            if(target == matrix[i][j]) return true;
            else if(target > matrix[i][j]) i++;
            else j--;
        }
        return false;
    }
};

 

[二分搜索] leetcode 240 Search a 2D Matrix II

原文:https://www.cnblogs.com/fish1996/p/11335373.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!