Skip to content

Commit 8c0ca37

Browse files
committed
feat: add js solution to lc problem: No.3016
1 parent 305fef5 commit 8c0ca37

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

solution/3000-3099/3016.Minimum Number of Pushes to Type Word II/README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,23 @@ function minimumPushes(word: string): number {
189189
}
190190
```
191191

192+
#### JavaScript
193+
194+
```js
195+
function minimumPushes(word) {
196+
const cnt = Array(26).fill(0);
197+
for (const c of word) {
198+
++cnt[c.charCodeAt(0) - 'a'.charCodeAt(0)];
199+
}
200+
cnt.sort((a, b) => b - a);
201+
let ans = 0;
202+
for (let i = 0; i < 26; ++i) {
203+
ans += (((i / 8) | 0) + 1) * cnt[i];
204+
}
205+
return ans;
206+
}
207+
```
208+
192209
<!-- tabs:end -->
193210

194211
<!-- solution:end -->

solution/3000-3099/3016.Minimum Number of Pushes to Type Word II/README_EN.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,23 @@ function minimumPushes(word: string): number {
187187
}
188188
```
189189

190+
#### JavaScript
191+
192+
```js
193+
function minimumPushes(word) {
194+
const cnt = Array(26).fill(0);
195+
for (const c of word) {
196+
++cnt[c.charCodeAt(0) - 'a'.charCodeAt(0)];
197+
}
198+
cnt.sort((a, b) => b - a);
199+
let ans = 0;
200+
for (let i = 0; i < 26; ++i) {
201+
ans += (((i / 8) | 0) + 1) * cnt[i];
202+
}
203+
return ans;
204+
}
205+
```
206+
190207
<!-- tabs:end -->
191208

192209
<!-- solution:end -->
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
function minimumPushes(word) {
2+
const cnt = Array(26).fill(0);
3+
for (const c of word) {
4+
++cnt[c.charCodeAt(0) - 'a'.charCodeAt(0)];
5+
}
6+
cnt.sort((a, b) => b - a);
7+
let ans = 0;
8+
for (let i = 0; i < 26; ++i) {
9+
ans += (((i / 8) | 0) + 1) * cnt[i];
10+
}
11+
return ans;
12+
}

0 commit comments

Comments
 (0)