Merge remote-tracking branch 'origin/master'

# Conflicts:
#	.idea/workspace.xml
pull/6/head
yuanguangxin 5 years ago
commit 07dcd591c7

@ -55,6 +55,7 @@
* [q54_螺旋矩阵](/src/数组操作/q54_螺旋矩阵)
* [q73_矩阵置零](/src/数组操作/q73_矩阵置零)
* [q78_子集](/src/数组操作/q78_子集)
* [q581_最短无序连续子数组](/src/数组操作/q581_最短无序连续子数组)
* [q945_使数组唯一的最小增量](/src/数组操作/q945_使数组唯一的最小增量)
### 栈相关

@ -0,0 +1,32 @@
package .q581_;
import java.util.Arrays;
/**
* o(n*log(n))
*/
public class Solution {
public int findUnsortedSubarray(int[] nums) {
if (nums == null || nums.length < 1) {
return 0;
}
int[] cloneNums = nums.clone();
Arrays.sort(nums);
int begin = Integer.MAX_VALUE;
int end = 0;
for (int i = 0; i < nums.length; i++) {
if (nums[i] != cloneNums[i]) {
begin = Math.min(begin, i);
end = Math.max(end, i);
}
}
return Math.max(end - begin + 1, 0);
}
public static void main(String[] args) {
new Solution().findUnsortedSubarray(new int[]{2, 6, 4, 8, 10, 9, 15});
}
}
Loading…
Cancel
Save