当前位置:网站首页>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;
}
};
边栏推荐
- Zip and Items() difference
- Unity C script implements AES encryption and decryption
- 线程有哪些状态?
- Android studio mobile development creates a new database and obtains picture and text data from the database to display on the listview list
- On the normalization of camera rotation interpolation
- Highlight detection with pairwise deep ranking for first person video summary (thesis translation)
- Unity3d display FPS script
- Directx11 advanced tutorial cluster based deffered shading
- Explanation of sensor flicker/banding phenomenon
- Unity3d multi platform method for reading text files in streamingasset directory
猜你喜欢

Opencv_ 100 questions_ Chapter V (21-25)

Computer composition and design work06 —— 基于MIPS

Tips for using the potplayer video player

Multithreading (V) -- Concurrent tools (II) -- j.u.c concurrent contracting (I) -- AQS and reentrantlock principles

Piecewise Bezier curve

The vs 2019 community version Microsoft account cannot be logged in and activated offline

MNIST handwritten data recognition by RNN

关于 Sensor flicker/banding现象的解释

Redis configuration (IV) -- cluster

Understand Houdini's (heightfield) remap operation
随机推荐
SQLite cross compile dynamic library
夜神模擬器adb查看log
Dlib face detection
交叉编译libev
Textcnn (MR dataset - emotion classification)
Leetcode January 10 daily question 306 Additive number
Redis application (I) -- distributed lock
Leetcode-1512. Number of good pairs
The first principle of thinking method
Leetcode-93. Restore IP address
RNN implementation regression model
Leetcode-1705. Maximum number of apples to eat
PHP 开发环境搭建及数据库增删改查
Video based fire smoke detection using robust AdaBoost
Using hidden Markov model to mark part of speech
线程有哪些状态?
Unity custom translucent surface material shader
MNIST handwritten data recognition by RNN
Jetson TX2 machine brushing jetpack4.2 (self test successful version)
First note