Skip to content

Commit 97ad745

Browse files
committed
adding leetcode75
1 parent ba15bf0 commit 97ad745

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// https://leetcode.com/problems/sort-colors/description/
2+
3+
4+
/**
5+
* @param {number[]} nums
6+
* @return {void} Do not return anything, modify nums in-place instead.
7+
*/
8+
var sortColors = function(nums) {
9+
const freq = [0, 0, 0];
10+
11+
for(const num of nums){
12+
freq[num]++;
13+
}
14+
15+
let index = 0;
16+
17+
for(let i=0; i<3; i++){
18+
for(let j=0; j<freq[i]; j++){
19+
nums[index++] = i;
20+
}
21+
}
22+
};
23+

0 commit comments

Comments
 (0)