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;
    }
};
相关推荐
code小毛孩1 小时前
leetcode hot100数组:缺失的第一个正数
数据结构·算法·leetcode
快去睡觉~11 小时前
力扣400:第N位数字
数据结构·算法·leetcode
gzzeason13 小时前
LeetCode Hot100:递归穿透值传递问题
算法·leetcode·职场和发展
qq_5139704416 小时前
力扣 hot100 Day74
数据结构·算法·leetcode
墨染点香19 小时前
LeetCode 刷题【42. 接雨水】
算法·leetcode·职场和发展
এ᭄画画的北北1 天前
力扣-347.前K个高频元素
算法·leetcode
亮亮爱刷题1 天前
算法提升之树上问题-(LCA)
数据结构·算法·leetcode·深度优先
火车叨位去19491 天前
力扣top100(day03-01)--二叉树 03
算法·leetcode·职场和发展
岁忧1 天前
(LeetCode 每日一题) 1780. 判断一个数字是否可以表示成三的幂的和 (数学、三进制数)
java·c++·算法·leetcode·职场和发展·go
胖咕噜的稞达鸭2 天前
数据结构---关于复杂度的基础解析与梳理
c语言·数据结构·算法·leetcode