count to 1 (since the first element is always part of the wiggle subsequence).diff between the current element and the previous one.diff is positive and prevdiff is non-positive, or diff is negative and prevdiff is non-negative, increment count.diff is not zero, update prevdiff to diff.count as the length of the longest wiggle subsequence.