File tree 3 files changed +58
-0
lines changed
solution/1100-1199/1189.Maximum Number of Balloons
3 files changed +58
-0
lines changed Original file line number Diff line number Diff line change @@ -86,6 +86,27 @@ class Solution {
86
86
}
87
87
```
88
88
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
+
89
110
### ** C++**
90
111
91
112
``` cpp
Original file line number Diff line number Diff line change @@ -77,6 +77,27 @@ class Solution {
77
77
}
78
78
```
79
79
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
+
80
101
### ** C++**
81
102
82
103
``` cpp
Original file line number Diff line number Diff line change
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
+ } ;
You can’t perform that action at this time.
0 commit comments