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;
    }
};
相关推荐
‎ദ്ദിᵔ.˛.ᵔ₎1 小时前
c++11:fuction包装器
开发语言·c++
霍霍的袁2 小时前
【C++】哈希表实现指南:从原理到开放定址法、链地址法的实现
c++·学习·哈希算法·散列表·visual studio
WL学习笔记3 小时前
类和对象(下)
c++·类和对象
Nil2083 小时前
leetcode 300最长递增子序列
算法·leetcode·职场和发展
傲世仙尊3 小时前
拷贝构造-传值传参的连锁反应与隐式函数的三个局限
c++
垆边人似月.4 小时前
华为机试题 :最大数
c++·算法·华为
方便面不加香菜4 小时前
C++ 关于多态的知识点讲解
开发语言·c++
yi0114 小时前
LeetCode 424. 替换后的最长重复字符|不定长滑动窗口:如何判断窗口是否合法?
笔记·python·算法·leetcode·双指针·滑动窗口
jimy15 小时前
C++ 类成员函数的内联定义(inline)详解
开发语言·c++
sanqima5 小时前
CreateThread、_beginthreadex、AfxBeginThread三种线程创建的区别与联系
c++·tls·线程创建