Skip to content

Commit 313a008

Browse files
committed
feat: add js solution to lc problem: No.3016
1 parent 092341a commit 313a008

File tree

3 files changed

+70
-0
lines changed

3 files changed

+70
-0
lines changed

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,31 @@ function minimumPushes(word: string): number {
241241
}
242242
```
243243

244+
#### JavaScript
245+
246+
```js
247+
function minimumPushes(word) {
248+
const pq = new MaxPriorityQueue();
249+
const cnt = new Map();
250+
let [i, res] = [0, 0];
251+
252+
for (const x of word) {
253+
cnt.set(x, (cnt.get(x) ?? 0) + 1);
254+
}
255+
256+
for (const [x, c] of cnt) {
257+
pq.enqueue(x, c);
258+
}
259+
260+
while (!pq.isEmpty()) {
261+
const c = pq.dequeue().priority;
262+
res += c * (((i++ / 8) | 0) + 1);
263+
}
264+
265+
return res;
266+
}
267+
```
268+
244269
<!-- tabs:end -->
245270
246271
<!-- solution:end -->

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,31 @@ function minimumPushes(word: string): number {
239239
}
240240
```
241241

242+
#### JavaScript
243+
244+
```js
245+
function minimumPushes(word) {
246+
const pq = new MaxPriorityQueue();
247+
const cnt = new Map();
248+
let [i, res] = [0, 0];
249+
250+
for (const x of word) {
251+
cnt.set(x, (cnt.get(x) ?? 0) + 1);
252+
}
253+
254+
for (const [x, c] of cnt) {
255+
pq.enqueue(x, c);
256+
}
257+
258+
while (!pq.isEmpty()) {
259+
const c = pq.dequeue().priority;
260+
res += c * (((i++ / 8) | 0) + 1);
261+
}
262+
263+
return res;
264+
}
265+
```
266+
242267
<!-- tabs:end -->
243268
244269
<!-- solution:end -->
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
function minimumPushes(word) {
2+
const pq = new MaxPriorityQueue();
3+
const cnt = new Map();
4+
let [i, res] = [0, 0];
5+
6+
for (const x of word) {
7+
cnt.set(x, (cnt.get(x) ?? 0) + 1);
8+
}
9+
10+
for (const [x, c] of cnt) {
11+
pq.enqueue(x, c);
12+
}
13+
14+
while (!pq.isEmpty()) {
15+
const c = pq.dequeue().priority;
16+
res += c * (((i++ / 8) | 0) + 1);
17+
}
18+
19+
return res;
20+
}

0 commit comments

Comments
 (0)