I used the built-in max and min function in python, that will speed up this to beat 81% people...

class Solution(object):
def findUnsortedSubarray(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
start, end = 0, len(nums) - 1
while start < len(nums) - 1 and nums[start] <= nums[start + 1]:
start += 1
if start == len(nums) - 1:
return 0
while end > 0 and nums[end] >= nums[end - 1]:
end -= 1
vmin = min(nums[start:(end + 1)])
vmax = max(nums[start:(end + 1)])
while start >= 0 and nums[start] > vmin:
start -= 1
while end <= len(nums) - 1 and nums[end] < vmax:
end += 1
return end - start - 1