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;
    }
};
相关推荐
pay顿6 分钟前
C++基础day1
c++·学习·笔试
孤寂码农_defector7 分钟前
C++【iostream】数据库的部分函数功能介绍
c++
Icomi_24 分钟前
【PyTorch】7.自动微分模块:开启神经网络 “进化之门” 的魔法钥匙
c语言·c++·人工智能·pytorch·python·机器学习·计算机视觉
余辉zmh25 分钟前
【贪心算法篇】:“贪心”之旅--算法练习题中的智慧与策略(二)
c++·算法·leetcode·贪心算法
余辉zmh35 分钟前
【贪心算法篇】:“贪心”之旅--算法练习题中的智慧与策略(一)
c++·算法·leetcode·贪心算法
taoyong0011 小时前
代码随想录算法训练营第三十七天-动态规划-完全背包-377. 组合总和 Ⅳ
c++·算法·leetcode·动态规划
阿豪学编程1 小时前
c++ string类 +底层模拟实现
开发语言·c++
-VE-2 小时前
myshell
linux·c++
Bluesonli3 小时前
第 1 天:UE5 C++ 开发环境搭建,全流程指南
开发语言·c++·ue5·虚幻·unreal engine
因兹菜3 小时前
[LeetCode]day4 977.有序数组的平方
数据结构·算法·leetcode