class Solution {
public:
int wiggleMaxLength(vector<int>& nums) {
int preD=0;
int curD=0;
int cnt=1;
for(int i=1; i<nums.size(); i++){
curD=nums[i]-nums[i-1];
if((curD>0 && preD<=0) || (curD<0 && preD>=0)){
cnt++;
preD=curD;
}
}
return cnt;
}
};
Leetcode 376 wiggle-subsequence 贪心
最新推荐文章于 2021-08-11 10:50:00 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)