Hi, this is Shunchi!

  • Home

  • Tags0

  • Archives267

  • Categories0

  • Curricula

  • DSA

  • LeetCode_Notes

  • Interviews

  • General

  • Resume

75. Sort Colors

Posted on 2020-10-06 | Edited on 2021-01-22

LeetCode

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
class Solution {
public void sortColors(int[] nums) {
int p0=0,curr=0,p2=nums.length-1;
while(curr<=p2){
if(nums[curr]==0){
nums[curr]=nums[p0];
nums[p0]=0;
curr++;p0++;
}
else if(nums[curr]==2){
nums[curr]=nums[p2];
nums[p2]=2;
p2--;
}
else{
curr++;
}
}
}
}

<1…111213…267>
ShunchiZhou

ShunchiZhou

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