28/100. Shortest Unsorted Continuous Subarray

class Solution(object):
    def findUnsortedSubarray(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """
        i = 0
        j = len(nums)-1
        newNums = sorted(nums)
        
        while i<j:
            if newNums[i] == nums[i]:
                i += 1
            else:
                break
        
        while j>=0:
            if newNums[j] == nums[j]:
                j -= 1
            else:
                break
                
        return j-i+1 if (j-i+1)>0 else 0

相关文章:

  • 2022-12-23
  • 2021-07-08
  • 2022-12-23
  • 2021-05-05
  • 2022-02-13
  • 2021-07-27
  • 2022-01-19
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-12-19
  • 2021-11-18
  • 2021-10-27
  • 2021-04-06
  • 2022-01-19
  • 2022-12-23
相关资源
相似解决方案