1
class Solution {
2
public int findUnsortedSubarray(int[] nums) {
3
int[] numsClone = nums.clone();
4
Arrays.sort(nums);
5

6
int s = Integer.MAX_VALUE;
7
int e = Integer.MIN_VALUE;
8

9
for (int i = 0; i < nums.length; i++) {
10
if (numsClone[i] != nums[i]) {
11
s = Math.min(s, i);
12
e = Math.max(e, i);
13
}
14
}
15

16
if (s == Integer.MAX_VALUE || e == Integer.MIN_VALUE) {
17
return 0;
18
}
19

20
return e - s + 1;
21
}
22
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0