Skip to content

Commit 120618f

Browse files
refactor 581
1 parent 8b1a7be commit 120618f

File tree

1 file changed

+1
-18
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+1
-18
lines changed

src/main/java/com/fishercoder/solutions/_581.java

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,14 @@
22

33
import java.util.Arrays;
44

5-
/**
6-
* 581. Shortest Unsorted Continuous Subarray
7-
*
8-
* Given an integer array, you need to find one continuous subarray that if you only sort this subarray in ascending order, then the whole array will be sorted in ascending order, too.
9-
10-
You need to find the shortest such subarray and output its length.
11-
12-
Example 1:
13-
Input: [2, 6, 4, 8, 10, 9, 15]
14-
Output: 5
15-
Explanation: You need to sort [6, 4, 8, 10, 9] in ascending order to make the whole array sorted in ascending order.
16-
17-
Note:
18-
Then length of the input array is in range [1, 10,000].
19-
The input array may contain duplicates, so ascending order here means <=.
20-
21-
*/
225
public class _581 {
236

247
public static class Solution1 {
258
/**
269
* credit: https://discuss.leetcode.com/topic/89282/java-o-n-time-o-1-space
2710
* Use start and end to keep track of the minimum subarray nums[start...end] which must be sorted for the entire array nums.
2811
* If start < end < 0 at the end of the for loop, then the array is already fully sorted.
29-
*
12+
* <p>
3013
* Time: O(n)
3114
* Space: O(1)
3215
*/

0 commit comments

Comments
 (0)