题目
分析
代码
class Solution {
public:
int wiggleMaxLength(vector<int>& nums) {
if(nums.size() < 2) return nums.size();
int ret = 0,left = 0,right = 0;
for(int i = 0;i < nums.size()-1;i++){
right = nums[i+1] - nums[i];
if(right == 0) continue;
if(left * right <= 0) ret++;
left = right;
}
return ret+1;
}
};