-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolution.py
More file actions
32 lines (28 loc) · 998 Bytes
/
solution.py
File metadata and controls
32 lines (28 loc) · 998 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
class Solution(object):
def findUnsortedSubarray(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
start = None
end = None
max_value = None
min_value = None
for i in range(len(nums)):
if i > 0 and start == None and nums[i - 1] > nums[i]:
start = i - 1
end = i
max_value = nums[i - 1]
min_value = nums[i]
elif max_value != None and max_value < nums[i]:
max_value = nums[i]
elif max_value != None and max_value > nums[i]:
end = i
if min_value != None and nums[i] < min_value:
min_value = nums[i]
if start != None:
for i in range(start):
if nums[i] > min_value:
start = i
break
return end - start + 1 if end != None and start != None else 0