Skip to content

Commit d291f6d

Browse files
committed
Leetcode Solution
1 parent ace9201 commit d291f6d

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

sort-colors.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* @param {number[]} nums
3+
* @return {void} Do not return anything, modify nums in-place instead.
4+
*/
5+
var sortColors = function (nums) {
6+
var hashmap = {};
7+
for (var i in nums) {
8+
if (nums[i] in hashmap) {
9+
hashmap[nums[i]]++;
10+
} else {
11+
hashmap[nums[i]] = 1;
12+
}
13+
}
14+
15+
var k = 0;
16+
for (var j in hashmap) {
17+
while (hashmap[j] > 0) {
18+
hashmap[j]--;
19+
nums[k++] = parseInt(j);
20+
}
21+
j++;
22+
}
23+
};

0 commit comments

Comments
 (0)