We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent a8550cb commit dd4f143Copy full SHA for dd4f143
javascript/1189-maximum-number-of-balloons.js
@@ -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