class Solution {
public:
int findUnsortedSubarray(vector<int>& nums) {
if(nums.size()==0) return 0;
int i=0,j=nums.size()1;
vector<int> temp(nums);
sort(temp.begin(),temp.end());
while(1)
{
if(temp[i] == nums[i])
i++;
else
break;
}
while(1)
{
if(temp[j] == nums[j])
j;
else
break;
}
return ji>0? ji+1:0;
}
};
C++ Solution


You can look my O(n) solution which beats 100%: https://discuss.leetcode.com/topic/89457/consolutionwhichbeats100