0376.cpp (384B)
1 class Solution { 2 public: 3 int wiggleMaxLength(vector<int> &nums) { 4 if (nums.size() == 0) return 0; 5 int up = 1, down = 1; 6 for (int i = 1; i < nums.size(); i++) { 7 if (nums[i] < nums[i - 1]) 8 down = up + 1; 9 else if (nums[i] > nums[i - 1]) 10 up = down + 1; 11 } 12 return max(up, down); 13 } 14 };