Here is the solution:
function wiggleMaxLength(nums)
if length <= 1 then
return length
up := 1
down := 1
for i from 1 to length - 1
if nums[i] > nums[i-1] then
up := down + 1
else if nums[i] < nums[i-1] then
down := up + 1
return max(up, down)
Time: . Space: .
= length of longest wiggle ending with an up move. = ending with down move. Each move extends the opposite direction.