Skip to content

Commit c4fb62a

Browse files
committed
feat: add question 75
1 parent 671543d commit c4fb62a

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

75.颜色分类.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* @lc app=leetcode.cn id=75 lang=javascript
3+
*
4+
* [75] 颜色分类
5+
*/
6+
7+
// @lc code=start
8+
/**
9+
* @param {number[]} nums
10+
* @return {void} Do not return anything, modify nums in-place instead.
11+
*/
12+
var sortColors = function(nums) {
13+
const t = new Array(3).fill(0);
14+
for (const n of nums) {
15+
t[n]++;
16+
}
17+
let i = 0;
18+
let j = 0;
19+
while (i < t.length) {
20+
if (t[i] === 0) {
21+
i++;
22+
continue;
23+
}
24+
nums[j] = i;
25+
j++;
26+
t[i]--;
27+
}
28+
};
29+
// @lc code=end
30+

0 commit comments

Comments
 (0)