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;
    }
};
相关推荐
bybitq6 小时前
Leetcode-3780-Python
python·算法·leetcode
如何原谅奋力过但无声6 小时前
【力扣-Python-75】颜色分类(middle)
python·算法·leetcode
玖剹6 小时前
哈希表相关题目
数据结构·c++·算法·leetcode·哈希算法·散列表
练习时长一年8 小时前
LeetCode热题100(最小栈)
java·算法·leetcode
Tisfy8 小时前
LeetCode 955.删列造序 II:模拟(O(mn)) + 提前退出
算法·leetcode·字符串·题解·遍历
im_AMBER8 小时前
Leetcode 82 每个字符最多出现两次的最长子字符串 | 删掉一个元素以后全为 1 的最长子数组
c++·笔记·学习·算法·leetcode
java修仙传8 小时前
力扣hot100:旋转排序数组中找目标值
算法·leetcode·职场和发展
YGGP9 小时前
【Golang】LeetCode 287. 寻找重复数
开发语言·leetcode·golang
前端小白在前进9 小时前
力扣刷题:千位分割数
javascript·算法·leetcode
小年糕是糕手9 小时前
【C/C++刷题集】string类(一)
开发语言·数据结构·c++·算法·leetcode