카테고리 없음
[Leetcode] 1189. Maximum Number of Balloons 문제풀이
bluespacedev
2021. 9. 13. 22:40
https://leetcode.com/problems/maximum-number-of-balloons/
Maximum Number of Balloons - LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
문제 내용
섞여있는 문자중에 balloon 이라는 단어가 몇개 나오는지 출력
Input: text = "nlaebolko"
Output: 1
문제 풀이
알파벳이 몇개 나오는지만 확인하고
ballon 빈도수가 얼마나 되는지 출력한다.
class Solution {
public:
int maxNumberOfBalloons(string text) {
int freq[26] = {0};
for (auto c : text)
freq[c-'a']++;
int number = 0;
vector<int> ballon = {0, 1, 11, 11, 14, 14, 13};
while(1) {
for (auto i : ballon) {
if (freq[i] == 0)
return number;
freq[i]--;
}
number++;
}
return number;
}
};