class Solution {
public int findUnsortedSubarray(int[] nums) {
int n=nums.length,star=0,end=-1,max=nums[0],min=nums[n-1];
for(int i=1;i<n;i++){
max=Math.max(max,nums[i]);
min=Math.min(min,nums[n-1-i]);
if(max>nums[i]) end=i;
if(min<nums[n-i-1]) star=n-1-i;
}
return end-star+1;
}
}
leetcode 581 Shortest Unsorted Continuous Subarray
最新推荐文章于 2024-08-29 18:44:48 发布