Skip to content

Commit dd4f143

Browse files
authored
Create 1189-maximum-number-of-balloons.js
Solved maximum-number-of-balloons in JS
1 parent a8550cb commit dd4f143

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

Diff for: javascript/1189-maximum-number-of-balloons.js

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// problem link https://leetcode.com/problems/maximum-number-of-balloons
2+
// time complexity O(n)
3+
4+
var maxNumberOfBalloons = function(text) {
5+
6+
const balloonCach = {};
7+
8+
for(let i = 0; i < text.length; i++) {
9+
if('balloon'.includes(text[i])) {
10+
if(balloonCach[text[i]]) {
11+
balloonCach[text[i]] += 1;
12+
} else {
13+
balloonCach[text[i]] = 1;
14+
}
15+
}
16+
}
17+
18+
let min = Math.min(balloonCach['b'],
19+
balloonCach['a'],
20+
balloonCach['n'],
21+
Math.floor(balloonCach['l']/2),
22+
Math.floor(balloonCach['o']/2));
23+
24+
return min ? min : 0;
25+
};

0 commit comments

Comments
 (0)