Hi, this is Shunchi!

  • Home

  • Tags0

  • Archives267

  • Categories0

  • Curricula

  • DSA

  • LeetCode_Notes

  • Interviews

  • General

  • Resume

581. Shortest Unsorted Continuous Subarray

Posted on 2020-09-09 | Edited on 2021-01-22

LeeCode

Sorting

1
2
3
4
5
6
7
8
9
10
class Solution {
public int findUnsortedSubarray(int[] nums) {
int[] sortedNums=nums.clone();
Arrays.sort(sortedNums);
int i=0,j=nums.length-1;
while(i<nums.length&&nums[i]==sortedNums[i]) i++;
while(j>=0&&j>i&&nums[j]==sortedNums[j]) j--;
return j-i+1;
}
}

<1…181920…267>
ShunchiZhou

ShunchiZhou

267 posts
RSS
GitHub E-Mail Gitbook Linkedin
© 2024 ShunchiZhou
Powered by Hexo v5.4.0
|
0%