We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent db46f93 commit 7e4f047Copy full SHA for 7e4f047
solution/0581.Shortest Unsorted Continuous Subarray/Solution2.java
@@ -0,0 +1,15 @@
1
+class Solution {
2
+ public int findUnsortedSubarray(int[] nums) {
3
+ int[] numArrs = nums.clone();
4
+ Arrays.sort(numArrs);
5
+
6
+ int start = numArrs.length, end = 0;
7
+ for (int i = 0; i < numArrs.length; i++) {
8
+ if (numArrs[i] != nums[i]) {
9
+ start = Math.min(start, i);
10
+ end = Math.max(end, i);
11
+ }
12
13
+ return (end - start >= 0 ? end - start + 1 : 0);
14
15
+}
0 commit comments