DP:

```
class Solution {
public:
int wiggleMaxLength(vector<int>& nums) {
int size=nums.size();
if(size==0) return 0;
vector<int> f(size, 1);
vector<int> d(size, 1);
for(int i=1; i<size; ++i){
for(int j=0; j<i; ++j){
if(nums[j]<nums[i]){
f[i]=max(f[i], d[j]+1);
}
else if(nums[j]>nums[i]){
d[i]=max(d[i], f[j]+1);
}
}
}
return max(d.back(), f.back());
}
};
```

Greedy:

```
class Solution {
public:
int wiggleMaxLength(vector<int>& nums) {
int size=nums.size(), f=1, d=1;
for(int i=1; i<size; ++i){
if(nums[i]>nums[i-1]) f=d+1;
else if(nums[i]<nums[i-1]) d=f+1;
}
return min(size, max(f, d));
}
};
```