C++ | Leetcode C++题解之第240题搜索二维矩阵II

题目:

题解:

cpp 复制代码
class Solution {
public:
    bool searchMatrix(vector<vector<int>>& matrix, int target) {
        int m = matrix.size(), n = matrix[0].size();
        int x = 0, y = n - 1;
        while (x < m && y >= 0) {
            if (matrix[x][y] == target) {
                return true;
            }
            if (matrix[x][y] > target) {
                --y;
            }
            else {
                ++x;
            }
        }
        return false;
    }
};
相关推荐
2401_884602274 小时前
程序人生-Hello’s P2P
c语言·c++
Charlie_lll4 小时前
力扣解题-637. 二叉树的层平均值
算法·leetcode
初中就开始混世的大魔王4 小时前
2 Fast DDS Library概述
c++·中间件·信息与通信
滴滴答滴答答5 小时前
机考刷题之 6 LeetCode 169 多数元素
算法·leetcode·职场和发展
圣保罗的大教堂5 小时前
leetcode 1980. 找出不同的二进制字符串 中等
leetcode
娇娇yyyyyy5 小时前
C++基础(6):extern解决重定义问题
c++
Neteen5 小时前
【数据结构-思维导图】第二章:线性表
数据结构·c++·算法
礼拜天没时间.5 小时前
力扣热题100实战 | 第25期:K个一组翻转链表——从两两交换到K路翻转的进阶之路
java·算法·leetcode·链表·递归·链表反转·k个一组翻转链表
Swift社区6 小时前
LeetCode 400 第 N 位数字
算法·leetcode·职场和发展
再难也得平6 小时前
力扣239. 滑动窗口最大值(Java解法)
算法·leetcode·职场和发展