Another python solution


  • 0
    J
    class Solution(object):
        def wiggleMaxLength(self, nums):
            """
            :type nums: List[int]
            :rtype: int
            """
            if nums == []:
                return 0
            
            count, status = 1, 0
            
            for i in range(1, len(nums)):
                if not curr_status:
                    curr_status = nums[i] - nums[i-1]
                    
                if nums[i] - nums[i-1] > 0 and curr_status > 0:
                    count += 1
                    curr_status = -1
                elif nums[i] - nums[i-1] < 0 and curr_status < 0:
                    count += 1
                    curr_status = 1
                
            return count
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.