Skip to content

Commit 902743e

Browse files
authored
Create 1189-maximum-number-of-balloons.js
1 parent d64bb4a commit 902743e

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

1189-maximum-number-of-balloons.js

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/**
2+
* @param {string} text
3+
* @return {number}
4+
*/
5+
const maxNumberOfBalloons = function(text) {
6+
const cnt = [...text].reduce((A, ch) => {
7+
A[ch] = (A[ch] || 0) + 1;
8+
return A;
9+
}, {});
10+
const ans = Math.min(cnt['b'], cnt['a'], cnt['l'] / 2, cnt['o'] / 2, cnt['n']);
11+
return ans ? Math.floor(ans) : 0;
12+
};

0 commit comments

Comments
 (0)