当前位置:网站首页>LeetCode-1189. Maximum number of balloons
LeetCode-1189. Maximum number of balloons
2022-06-12 06:23:00 【Border wanderer】
Give you a string text, You need to use text To piece together as many words as possible "balloon"( balloon ).
character string text Each letter in can only be used once at most . Please return the maximum number of words you can piece together "balloon".
Example 1:

Input :text = "nlaebolko"
Output :1
Example 2:

Input :text = "loonbalxballpoon"
Output :2
Example 3:
Input :text = "leetcode"
Output :0
Tips :
1 <= text.length <= 10^4
text All consist of lowercase English letters
#include<iostream>
#include<unordered_map>
#include<unordered_set>
using namespace std;
class Solution {
public:
int maxNumberOfBalloons(string text) {
int minval = INT_MAX;
std::string str = "balloon";
unordered_set<char> filter; /* Record whether to access all */
unordered_map<char, int>::iterator it;
unordered_map<char, int> cur;
unordered_map<char, int> mp;
mp['b'] = 1;
mp['a'] = 1;
mp['l'] = 2;
mp['o'] = 2;
mp['n'] = 1;
for (char c : text) {
if (cur.count(c) == 0) {
cur[c] = 1;
}
else {
cur[c]++;
}
}
it = cur.begin();
while (it != cur.end()) {
if (mp.count(it->first) != 0) {
filter.insert(it->first);
if ((cur[it->first] / mp[it->first]) < minval) {
minval = cur[it->first] / mp[it->first];
}
}
it++;
}
if (filter.size() != 5) {
minval = 0;
}
return minval;
}
};
边栏推荐
- Houdini & UE4 programmed generation of mountains and multi vegetation scattering points
- Unreal Engine learning notes
- UE4 4.27 modify the mobile forward pipeline to support cluster multi light source culling
- leetcode 704. Binary search
- SQL注入——联合查询union
- Summary of some problems in sensor bring up
- What states do threads have?
- 姿态估计之2D人体姿态估计 - PifPaf:Composite Fields for Human Pose Estimation
- QT--实现TCP通信
- Analysis of memory management mechanism of (UE4 4.26) UE4 uobject
猜你喜欢

Findasync and include LINQ statements - findasync and include LINQ statements

Sqlite Cross - compile Dynamic Library

Cv2.fillpoly coco annotator segment coordinate conversion to mask image

Leetcode January 13 daily question 747 At least twice the maximum number of other numbers

N-degree Bessel curve

Cause analysis of motion blur / smear caused by camera shooting moving objects

关于 Sensor flicker/banding现象的解释

Using hidden Markov model to mark part of speech

(UE4 4.27) customize primitivecomponent

Redis configuration (IV) -- cluster
随机推荐
Research Report on truffle fungus industry - market status analysis and development prospect forecast
leetcode 300. Longest increasing subsequence
摄像头拍摄运动物体,产生运动模糊/拖影的原因分析
Word vector training based on nnlm
Redis application (I) -- distributed lock
基于报错的 SQL 注入
GET 和 POST 的区别及留言板代码实现
Analysis of memory management mechanism of (UE4 4.26) UE4 uobject
Houdini terrain creation
Multithreading Foundation (XI) -- prevent CPU from occupying 100%
Get the size of the picture
. Net core and Net framework comparison
Opencv_100问_第五章 (21-25)
LeetCode-1154. Day of the year
Video summary with long short term memory
468. verifying the IP address
AI作业ch8
English grammar_ Adverb_ With or without ly, the meaning is different
Computer composition and design work06 —— 基于MIPS
Qt-- realize TCP communication