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;
    }
};
相关推荐
人工智能AI技术21 分钟前
GitHub Copilot 2026新功能实操:C++跨文件上下文感知开发,效率翻倍技巧
c++·人工智能
鱼跃鹰飞23 分钟前
Leetcode尊享面试100题:1060. 有序数组中的缺失元素
算法·leetcode·面试
大志若愚YYZ1 小时前
ROS2学习 C++中的this指针
c++·学习·算法
sprintzer1 小时前
1.6-1.15力扣数学刷题
算法·leetcode·职场和发展
玖釉-1 小时前
[Vulkan 学习之路] 16 - 最终章:渲染循环与同步 (Rendering & Presentation)
c++·windows·图形渲染
踩坑记录1 小时前
leetcode hot100 53.最大子数组和 动态规划 medium
leetcode·动态规划
狗狗学不会2 小时前
Pybind11 封装 RK3588 全流程服务:Python 写逻辑,C++ 跑并发,性能起飞!
c++·人工智能·python·目标检测
DYS_房东的猫2 小时前
《 C++ 零基础入门教程》第10章:C++20 核心特性 —— 编写更现代、更优雅的 C++
java·c++·c++20
Howrun7772 小时前
虚幻引擎_AController_APlayerController_AAIController
开发语言·c++·游戏引擎·虚幻
小林rr2 小时前
深入探索 C++:现代特性、工程实践与性能优化全解
java·c++·性能优化