Skip to content

Commit 2402e98

Browse files
committed
Runtime: 146 ms (Top 27.63%) | Memory: 47.5 MB (Top 55.26%)
1 parent 00d363c commit 2402e98

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,26 @@
1+
// Runtime: 146 ms (Top 27.63%) | Memory: 47.5 MB (Top 55.26%)
12
var countLargestGroup = function(n) {
23
const hash = {};
34

45
for (let i = 1; i <= n; i++) {
56
const sum = i.toString().split('').reduce((r, x) => r + parseInt(x), 0);
6-
7+
78
if (!hash[sum]) {
89
hash[sum] = 0;
910
}
10-
11+
1112
hash[sum]++;
1213
}
13-
14+
1415
return Object.keys(hash)
1516
.sort((a, b) => hash[b] - hash[a])
1617
.reduce((res, x) => {
1718
const prev = res[res.length - 1];
18-
19+
1920
if (!prev || prev === hash[x]) {
2021
res.push(hash[x]);
2122
}
22-
23+
2324
return res;
2425
}, []).length;
25-
};
26+
};

0 commit comments

Comments
 (0)