C++ | Leetcode C++题解之第334题递增的三元子序列

题目:

题解:

cpp 复制代码
class Solution {
public:
    bool increasingTriplet(vector<int>& nums) {
        int n = nums.size();
        if (n < 3) {
            return false;
        }
        int first = nums[0], second = INT_MAX;
        for (int i = 1; i < n; i++) {
            int num = nums[i];
            if (num > second) {
                return true;
            } else if (num > first) {
                second = num;
            } else {
                first = num;
            }
        }
        return false;
    }
};
相关推荐
j_xxx404_22 分钟前
力扣困难算法精解:串联所有单词的子串与最小覆盖子串
java·开发语言·c++·算法·leetcode·哈希算法
big_rabbit050237 分钟前
[算法][力扣167]Two Sum II
算法·leetcode·职场和发展
筱砚.1 小时前
C++——lambda
开发语言·c++·算法
Eward-an1 小时前
LeetCode 76. 最小覆盖子串(详细技术解析)
python·算法·leetcode·职场和发展
不想看见4042 小时前
Reverse Bits位运算基础问题--力扣101算法题解笔记
笔记·算法·leetcode
逆境不可逃2 小时前
LeetCode 热题 100 之 394. 字符串解码 739. 每日温度 84. 柱状图中的最大矩形
算法·leetcode·职场和发展
sycmancia2 小时前
C++——动态内存分配、关于虚函数、关于继承中的强制类型转换
开发语言·c++
重生之后端学习3 小时前
62. 不同路径
开发语言·数据结构·算法·leetcode·职场和发展·深度优先
big_rabbit05023 小时前
[算法][力扣283]Move Zeros
算法·leetcode·职场和发展
重生之后端学习3 小时前
64. 最小路径和
数据结构·算法·leetcode·排序算法·深度优先·图论