File tree 3 files changed +124
-0
lines changed
solution/1100-1199/1189.Maximum Number of Balloons
3 files changed +124
-0
lines changed Original file line number Diff line number Diff line change @@ -107,6 +107,30 @@ function maxNumberOfBalloons(text: string): number {
107
107
};
108
108
```
109
109
110
+ ``` ts
111
+ function maxNumberOfBalloons(text : string ): number {
112
+ const map = new Map ([
113
+ [' b' , 0 ],
114
+ [' a' , 0 ],
115
+ [' l' , 0 ],
116
+ [' o' , 0 ],
117
+ [' n' , 0 ],
118
+ ]);
119
+ for (const c of text ) {
120
+ if (map .has (c )) {
121
+ map .set (c , map .get (c ) + 1 );
122
+ }
123
+ }
124
+ map .set (' l' , Math .floor (map .get (' l' ) / 2 ));
125
+ map .set (' o' , Math .floor (map .get (' o' ) / 2 ));
126
+ let res = Infinity ;
127
+ for (const value of map .values ()) {
128
+ res = Math .min (res , value );
129
+ }
130
+ return res ;
131
+ }
132
+ ```
133
+
110
134
### ** C++**
111
135
112
136
``` cpp
@@ -151,6 +175,33 @@ func min(a, b int) int {
151
175
}
152
176
```
153
177
178
+ ### ** Rust**
179
+
180
+ ``` rust
181
+ impl Solution {
182
+ pub fn max_number_of_balloons (text : String ) -> i32 {
183
+ let mut arr = [0 ; 5 ];
184
+ for c in text . chars () {
185
+ match c {
186
+ 'b' => arr [0 ] += 1 ,
187
+ 'a' => arr [1 ] += 1 ,
188
+ 'l' => arr [2 ] += 1 ,
189
+ 'o' => arr [3 ] += 1 ,
190
+ 'n' => arr [4 ] += 1 ,
191
+ _ => {}
192
+ }
193
+ }
194
+ arr [2 ] /= 2 ;
195
+ arr [3 ] /= 2 ;
196
+ let mut res = 0 ;
197
+ for num in arr {
198
+ res = res . min (num );
199
+ }
200
+ res
201
+ }
202
+ }
203
+ ```
204
+
154
205
### ** ...**
155
206
156
207
```
Original file line number Diff line number Diff line change @@ -98,6 +98,30 @@ function maxNumberOfBalloons(text: string): number {
98
98
};
99
99
```
100
100
101
+ ``` ts
102
+ function maxNumberOfBalloons(text : string ): number {
103
+ const map = new Map ([
104
+ [' b' , 0 ],
105
+ [' a' , 0 ],
106
+ [' l' , 0 ],
107
+ [' o' , 0 ],
108
+ [' n' , 0 ],
109
+ ]);
110
+ for (const c of text ) {
111
+ if (map .has (c )) {
112
+ map .set (c , map .get (c ) + 1 );
113
+ }
114
+ }
115
+ map .set (' l' , Math .floor (map .get (' l' ) / 2 ));
116
+ map .set (' o' , Math .floor (map .get (' o' ) / 2 ));
117
+ let res = Infinity ;
118
+ for (const value of map .values ()) {
119
+ res = Math .min (res , value );
120
+ }
121
+ return res ;
122
+ }
123
+ ```
124
+
101
125
### ** C++**
102
126
103
127
``` cpp
@@ -142,6 +166,33 @@ func min(a, b int) int {
142
166
}
143
167
```
144
168
169
+ ### ** Rust**
170
+
171
+ ``` rust
172
+ impl Solution {
173
+ pub fn max_number_of_balloons (text : String ) -> i32 {
174
+ let mut arr = [0 ; 5 ];
175
+ for c in text . chars () {
176
+ match c {
177
+ 'b' => arr [0 ] += 1 ,
178
+ 'a' => arr [1 ] += 1 ,
179
+ 'l' => arr [2 ] += 1 ,
180
+ 'o' => arr [3 ] += 1 ,
181
+ 'n' => arr [4 ] += 1 ,
182
+ _ => {}
183
+ }
184
+ }
185
+ arr [2 ] /= 2 ;
186
+ arr [3 ] /= 2 ;
187
+ let mut res = 0 ;
188
+ for num in arr {
189
+ res = res . min (num );
190
+ }
191
+ res
192
+ }
193
+ }
194
+ ```
195
+
145
196
### ** ...**
146
197
147
198
```
Original file line number Diff line number Diff line change
1
+ impl Solution {
2
+ pub fn max_number_of_balloons ( text : String ) -> i32 {
3
+ let mut arr = [ 0 ; 5 ] ;
4
+ for c in text. chars ( ) {
5
+ match c {
6
+ 'b' => arr[ 0 ] += 1 ,
7
+ 'a' => arr[ 1 ] += 1 ,
8
+ 'l' => arr[ 2 ] += 1 ,
9
+ 'o' => arr[ 3 ] += 1 ,
10
+ 'n' => arr[ 4 ] += 1 ,
11
+ _ => { }
12
+ }
13
+ }
14
+ arr[ 2 ] /= 2 ;
15
+ arr[ 3 ] /= 2 ;
16
+ let mut res = 0 ;
17
+ for num in arr {
18
+ res = res. min ( num) ;
19
+ }
20
+ res
21
+ }
22
+ }
You can’t perform that action at this time.
0 commit comments