Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution(object):
- def wiggleMaxLength(self, nums):
- """
- :type nums: List[int]
- :rtype: int
- """
- if not nums or len(nums) == 1:
- return len(nums)
- current_num, prev_num = nums[0], nums[0]
- count, trend = 0, None
- for current_num in nums:
- if not trend:
- if current_num > prev_num:
- trend = "down_to_up"
- count += 2
- elif current_num < prev_num:
- trend = "up_to_down"
- count += 2
- elif trend == "down_to_up":
- if current_num < prev_num:
- count += 1
- trend = "up_to_down"
- elif trend == "up_to_down":
- if current_num > prev_num:
- prev_num = current_num
- count += 1
- trend = "down_to_up"
- prev_num = current_num
- if trend == None:
- count = 1
- return count
Add Comment
Please, Sign In to add comment