public int findUnsortedSubarray(int[] nums) {
int[] kk = new int[nums.length];
for(int i = 0;i<nums.length;i++){
kk[i] = nums[i];
}
Arrays.sort(kk);
int left = 0;
int right = 0;
for(int i = 0;i<nums.length;i++){
if (kk[i] != nums[i]){
left = i;
break;
}
}
for(int i = nums.length-1;i>=0;i--){
if (kk[i] != nums[i]){
right = i;
break;
}
}
if(left == right){
return 0;
}
return right-left+1;
}
网友评论