python - unsorted subarray


  • 0
    S
    class Solution(object):
        def findUnsortedSubarray(self, nums):
            """
            :type nums: List[int]
            :rtype: int
            """
            numsort = sorted(nums)
            left, right = 0, len(nums)-1
            
            while left < right and numsort[left] == nums[left]:
                left += 1
            
            while right > left and numsort[right] == nums[right]:
                right -= 1
            
            return right-left+1 if left != right else 0
    

Log in to reply
 

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