class Solution {
public:
int wiggleMaxLength(vector<int>& nums) {
int n = nums.size();
if (n == 1) return n;
int res = 0;
string direction{};
for (int i = 1; i < n; i++) {
if (nums[i] > nums[i - 1]) {
if (direction == "up") continue;
direction = "up";
res += 1;
} else if (nums[i] < nums[i - 1]) {
if (direction == "down") continue;
direction = "down";
res += 1;
}
}
return res + 1;
}
};