class Solution {
public:
int wiggleMaxLength(vector<int>& nums) {
if (nums.size() <= 1)
return nums.size();
int preDiff = 0;
int curDiff = 0;
int result = 1;
for (int i = 0; i < nums.size()-1; i++){
curDiff = nums[i+1] - nums[i];
if ((curDiff > 0 && preDiff <= 0) || (curDiff < 0 && preDiff >= 0)){
result++;
preDiff = curDiff;
}
// preDiff = curDiff;
//上坡或者下坡完全不用记录
//只有峰值的转折才需要记录
}
return result;
}
};