@@ -0,0 +1,1152 @@
+# Time:  O(n)%0A# Space: O(1)%0A%0A# Given an integer array, you need to find one continuous subarray that%0A# if you only sort this subarray in ascending order,%0A# then the whole array will be sorted in ascending order, too.%0A#%0A# You need to find the shortest such subarray and output its length.%0A#%0A# Example 1:%0A# Input: %5B2, 6, 4, 8, 10, 9, 15%5D%0A# Output: 5%0A# Explanation: You need to sort %5B6, 4, 8, 10, 9%5D in ascending order%0A# to make the whole array sorted in ascending order.%0A#%0A# Note:%0A# Then length of the input array is in range %5B1, 10,000%5D.%0A# The input array may contain duplicates, so ascending order here means %3C=.%0A%0Aclass Solution(object):%0A    def findUnsortedSubarray(self, nums):%0A        %22%22%22%0A        :type nums: List%5Bint%5D%0A        :rtype: int%0A        %22%22%22%0A        n = len(nums)%0A        left, right = -1, -2%0A        min_from_right, max_from_left = nums%5B-1%5D, nums%5B0%5D%0A        for i in xrange(1, n):%0A            max_from_left = max(max_from_left, nums%5Bi%5D)%0A            min_from_right = min(min_from_right, nums%5Bn-1-i%5D)%0A            if nums%5Bi%5D %3C max_from_left: right = i%0A            if nums%5Bn-1-i%5D %3E min_from_right: left = n-1-i%0A        return right - left + 1%0A

Create shortest-unsorted-continuous-subarray.py