Skip to content

Commit e4e3985

Browse files
committed
feat: add solutions to lc problem: No.1189
No.1189.Maximum Number of Balloons
1 parent 4e51c3a commit e4e3985

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed

solution/1100-1199/1189.Maximum Number of Balloons/README.md

+21
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,27 @@ class Solution {
8686
}
8787
```
8888

89+
### **TypeScript**
90+
91+
```ts
92+
function maxNumberOfBalloons(text: string): number {
93+
let targets: Set<string> = new Set('balloon'.split(''));
94+
let cnt = new Array(126).fill(0);
95+
for (let char of text) {
96+
if (targets.has(char)) {
97+
cnt[char.charCodeAt(0)]++;
98+
}
99+
}
100+
cnt['l'.charCodeAt(0)] >>= 1;
101+
cnt['o'.charCodeAt(0)] >>= 1;
102+
let ans = Number.MAX_SAFE_INTEGER;
103+
for (let char of targets) {
104+
ans = Math.min(cnt[char.charCodeAt(0)], ans);
105+
}
106+
return ans;
107+
};
108+
```
109+
89110
### **C++**
90111

91112
```cpp

solution/1100-1199/1189.Maximum Number of Balloons/README_EN.md

+21
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,27 @@ class Solution {
7777
}
7878
```
7979

80+
### **TypeScript**
81+
82+
```ts
83+
function maxNumberOfBalloons(text: string): number {
84+
let targets: Set<string> = new Set('balloon'.split(''));
85+
let cnt = new Array(126).fill(0);
86+
for (let char of text) {
87+
if (targets.has(char)) {
88+
cnt[char.charCodeAt(0)]++;
89+
}
90+
}
91+
cnt['l'.charCodeAt(0)] >>= 1;
92+
cnt['o'.charCodeAt(0)] >>= 1;
93+
let ans = Number.MAX_SAFE_INTEGER;
94+
for (let char of targets) {
95+
ans = Math.min(cnt[char.charCodeAt(0)], ans);
96+
}
97+
return ans;
98+
};
99+
```
100+
80101
### **C++**
81102

82103
```cpp
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
function maxNumberOfBalloons(text: string): number {
2+
let targets: Set<string> = new Set('balloon'.split(''));
3+
let cnt = new Array(126).fill(0);
4+
for (let char of text) {
5+
if (targets.has(char)) {
6+
cnt[char.charCodeAt(0)]++;
7+
}
8+
}
9+
cnt['l'.charCodeAt(0)] >>= 1;
10+
cnt['o'.charCodeAt(0)] >>= 1;
11+
let ans = Number.MAX_SAFE_INTEGER;
12+
for (let char of targets) {
13+
ans = Math.min(cnt[char.charCodeAt(0)], ans);
14+
}
15+
return ans;
16+
};

0 commit comments

Comments
 (0)