Skip to content

Commit e966d3a

Browse files
committedJun 23, 2024
Time: 155 ms (79.93%), Space: 17.8 MB (85.91%) - LeetHub
1 parent bc825a9 commit e966d3a

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class Solution:
2+
def findUnsortedSubarray(self, nums: List[int]) -> int:
3+
size = len(nums)
4+
current = nums[0]
5+
end = 0
6+
7+
for index in range(1, size):
8+
if nums[index] < current:
9+
end = index
10+
else:
11+
current = nums[index]
12+
13+
current = nums[-1]
14+
start = 0
15+
16+
for index in range(size - 2, -1, -1):
17+
if nums[index] > current:
18+
start = index
19+
else:
20+
current = nums[index]
21+
22+
return end - start + 1 if end != start else 0

0 commit comments

Comments
 (0)
Please sign in to comment.