376. Wiggle Subsequence

376. Wiggle Subsequence

代码

cpp 复制代码
class Solution {
public:
    int wiggleMaxLength(vector<int>& nums) {
        int n = nums.size();
        int res = 1;
        int prediff = 0;
        int curdiff = 0;
        for(int i = 0;i < n-1;i++){
            curdiff = nums[i+1] - nums[i];
            if( (prediff >= 0 && curdiff < 0) ||
                (prediff <= 0 && curdiff > 0)){
                    res++;
                    prediff = curdiff;
                }
        }
        return res;
    }
};
相关推荐
而后笑面对16 小时前
力扣2025.10.19每日一题
算法·leetcode·职场和发展
·白小白17 小时前
力扣(LeetCode) ——11.盛水最多的容器(C++)
c++·算法·leetcode
玩镜的码农小师兄20 小时前
[从零开始面试算法] (04/100) LeetCode 136. 只出现一次的数字:哈希表与位运算的巅峰对决
c++·算法·leetcode·面试·位运算·hot100
无敌最俊朗@1 天前
数组-力扣hot56-合并区间
数据结构·算法·leetcode
码农多耕地呗1 天前
力扣94.二叉树的中序遍历(递归and迭代法)(java)
数据结构·算法·leetcode
微笑尅乐1 天前
BFS 与 DFS——力扣102.二叉树的层序遍历
leetcode·深度优先·宽度优先
白云千载尽1 天前
leetcode 912.排序数组
算法·leetcode·职场和发展
代码充电宝1 天前
LeetCode 算法题【简单】290. 单词规律
java·算法·leetcode·职场和发展·哈希表
And_Ii1 天前
LeetCode 3397. 执行操作后不同元素的最大数量
数据结构·算法·leetcode
额呃呃1 天前
leetCode第33题
数据结构·算法·leetcode