Skip to content

Commit 5a1736a

Browse files
committed
feat: add typescript solution to lc problem: No.2244
No.2244.Minimum Rounds to Complete All Tasks
1 parent 9370f57 commit 5a1736a

File tree

3 files changed

+42
-2
lines changed

3 files changed

+42
-2
lines changed

solution/2200-2299/2244.Minimum Rounds to Complete All Tasks/README.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,20 @@
6565
### **TypeScript**
6666

6767
```ts
68-
68+
function minimumRounds(tasks: number[]): number {
69+
let hashMap = new Map();
70+
for (let key of tasks) {
71+
hashMap.set(key, (hashMap.get(key) || 0) + 1);
72+
}
73+
let ans = 0;
74+
for (let key of hashMap.keys()) {
75+
let val = hashMap.get(key);
76+
if (val < 2) return -1;
77+
const ctn = Math.floor(val / 3) + (val % 3 == 0 ? 0 : 1);
78+
ans += ctn;
79+
}
80+
return ans;
81+
};
6982
```
7083

7184
### **...**

solution/2200-2299/2244.Minimum Rounds to Complete All Tasks/README_EN.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,20 @@ It can be shown that all the tasks cannot be completed in fewer than 4 rounds, s
5757
### **TypeScript**
5858

5959
```ts
60-
60+
function minimumRounds(tasks: number[]): number {
61+
let hashMap = new Map();
62+
for (let key of tasks) {
63+
hashMap.set(key, (hashMap.get(key) || 0) + 1);
64+
}
65+
let ans = 0;
66+
for (let key of hashMap.keys()) {
67+
let val = hashMap.get(key);
68+
if (val < 2) return -1;
69+
const ctn = Math.floor(val / 3) + (val % 3 == 0 ? 0 : 1);
70+
ans += ctn;
71+
}
72+
return ans;
73+
};
6174
```
6275

6376
### **...**
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
function minimumRounds(tasks: number[]): number {
2+
let hashMap = new Map();
3+
for (let key of tasks) {
4+
hashMap.set(key, (hashMap.get(key) || 0) + 1);
5+
}
6+
let ans = 0;
7+
for (let key of hashMap.keys()) {
8+
let val = hashMap.get(key);
9+
if (val < 2) return -1;
10+
const ctn = Math.floor(val / 3) + (val % 3 == 0 ? 0 : 1);
11+
ans += ctn;
12+
}
13+
return ans;
14+
};

0 commit comments

Comments
 (0)