LeetCode 581. Shortest Unsorted Continuous Subarray Given an integer array, you need to find one continuous subarray that if you only sort this subarray in ascending order, then the whole array will be sorted in ascending order, too. You need to find the shortest such subarray and output its...
classSolution {publicintfindUnsortedSubarray(int[] nums) {if(nums ==null|| nums.length == 0)return0;intlen = nums.length, start = 1, end = 0;for(inti=0; i<len; i++)if(!judge(nums, i)) { start=i;break; }for(inti=len-1; i>start; i--)if(!judge(nums, i)) { end=i;...
publicclassSolution{publicintfindUnsortedSubarray(int[]nums){intmin=Integer.MAX_VALUE,max=Integer.MIN_VALUE;booleanflag=false;for(inti=1;i<nums.length;i++){if(nums[i]<nums[i-1])flag=true;if(flag)min=Math.min(min,nums[i]);}flag=false;for(inti=nums.length-2;i>=0;i--){if(nums[i...
Shortest Unsorted Continuous Subarray 题目描述: Given an integer array, you need to find one continuous subarray that if you only sort this subarray in ascending order, then the whole array will...leetcode 581. Shortest Unsorted Continuous Subarray 原题: Given an integer array, you need to ...
Runtime:7 ms, faster than46.53%of Java online submissions for Shortest Unsorted Continuous Subarray. Memory Usage:45.1 MB, less than77.94%of Java online submissions for Shortest Unsorted Continuous Subarray.
581. Shortest Unsorted Continuous Subarray Given an integer array, you need to find one continuous subarray that if you only sort this subarray in ascending order, then the whole array will be sorted in ascending order, too. You need......
leetcode 581[easy]--- Shortest Unsorted Continuous Subarray 难度:easy Given an integer array, you need to find onecontinuoussubarraythat if you only sort this... to find theshortestsuchsubarrayand output its length. 思路:找出需要重新进行排列的最小数列数,使array变成有序array。 唯有最小的 leet...
Shortest Unsorted Continuous Subarray 题目描述: Given an integer array, you need to find one continuous subarray that if you only sort this subarray in ascending order, then the whole array will...leetcode 581. Shortest Unsorted Continuous Subarray 原题: Given an integer array, you need to ...
Leetcode 581 Shortest Unsorted Continuous Subarray Given an integer array, you need to find one continuous subarray that if you only sort this subarray in ascending order, then the whole array will be sorted in ascending order, too. You need to find the shortest such subarray and output its ...
#include <stack> #include <string> #include <climits> #include <algorithm> #include <sstream> #include <functional> #include <bitset> #include <numeric> #include <cmath> using namespace std; class Solution { public: int findUnsortedSubarray(vector<int>& nums) ...