法一:排序
来源:力扣
// 法一: 排序public int findUnsortedSubarray(int[] nums) {int[] numsSorted = new int[nums.length];System.arraycopy(nums, 0, numsSorted, 0, nums.length);Arrays.sort(numsSorted);int left = 0;int right = nums.length - 1;while (nums[left] == numsSorted[left]) {left++;// 要是数组本来就是全部有序的,那么就会有这种情况if (left > right) {return 0;}}while (nums[right] == numsSorted[right]) {right--;}return right - left + 1;}
