Shortest Unsorted Continuous Subarray
Input:
[2, 6, 4, 8, 10, 9, 15]
Output:
5
Explanation:
You need to sort [6, 4, 8, 10, 9] in ascending order to make the whole array sorted in ascending order.class Solution(object):
def findUnsortedSubarray(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
n, sorts = len(nums), sorted(nums)
if nums == sorts: return 0
l, r = min(i for i in range(n) if nums[i] != sorts[i]), max(i for i in range(n) if nums[i] != sorts[i])
return r - l + 1Last updated