class Solution {
public:
int findUnsortedSubarray(vector<int>& nums) {
int n=nums.size();
int l=0,r=n-1;
while(l<n-1&&nums[l]<=nums[l+1]) l++;
while(r>0&&nums[r]>=nums[r-1]) r--;
int min_num=INT_MAX,max_num=INT_MIN;
if(l==n-1||r==0) return 0;
for(int i=0;i<r;i++) max_num=max(max_num,nums[i]);
for(int i=l;i<n;i++) min_num=min(min_num,nums[i]);
while(l>=0&&nums[l]>min_num) l--;
while(r<n&&nums[r]<max_num) r++;
return r-l-1;
}
};
标签:nums,int,581,最短,num,min,LeetCode
From: https://www.cnblogs.com/tangxibomb/p/17595955.html