```
class Solution(object):
def findUnsortedSubarray(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
ordered_array = sorted(nums)
res_map = [1 if x[0] != x[1] else 0 for x in zip(ordered_array, nums)]
if 0 not in res_map:
return len(nums)
if 1 not in res_map:
return 0
start = res_map.index(1)
end = len(nums) - res_map[::-1].index(1)
return end - start
```