We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 58fd73c commit 5fad49aCopy full SHA for 5fad49a
75-sort-colors.js
@@ -0,0 +1,25 @@
1
+/**
2
+ * @param {number[]} nums
3
+ * @return {void} Do not return anything, modify nums in-place instead.
4
+ */
5
+
6
+const sortColors = function(nums) {
7
+ const counts = {};
8
+ for (const n of nums) {
9
+ if (!counts[n]) counts[n] = 0;
10
+ counts[n]++;
11
+ }
12
13
+ let val = 0;
14
+ for (let i = 0; i < nums.length;) {
15
+ let count = counts[val];
16
+ while (count > 0) {
17
+ nums[i] = val;
18
+ count--;
19
+ i++;
20
21
+ val+=1;
22
23
24
+ return nums;
25
+};
0 commit comments