当前位置:网站首页>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;
}
};
边栏推荐
- cv2.fillPoly coco annotator segment坐标转化为mask图像
- Information content security experiment of Harbin Institute of Technology
- Unity surface shader with template buffer
- Single channel picture reading
- 摄像头拍摄运动物体,产生运动模糊/拖影的原因分析
- 相机图像质量概述
- LeetCode-1185. Day of the week
- Multithreading (4) -- no lock (3) -- longadder source code
- (UE4 4.27) customize globalshader
- Multithreading mode (I) -- protective pause and join source code
猜你喜欢

Redis队列

RMB classification II

Leetcode January 12 daily question 334 Increasing ternary subsequence

AI operation ch8

C2w model - language model

How do I get the date and time from the Internet- How to get DateTime from the internet?

Overview of camera image quality

First note

Jetson TX2 machine brushing jetpack4.2 (self test successful version)

N-degree Bessel curve
随机推荐
Unity custom translucent surface material shader
SQL 注入读写文件
Leetcode-1512. Number of good pairs
Unity implements smooth interpolation
Simple spiral ladder generation for Houdini program modeling
Automatic modeling of Interchange
leetcode 35. Search insert location
Leetcode-646. Longest number pair chain
JS预解析
Leetcode-139. Word splitting
English grammar_ Adverb_ With or without ly, the meaning is different
Leetcode January 12 daily question 334 Increasing ternary subsequence
Trunet: short videos generation from long videos via story preserving truncation (thesis translation)
PHP 开发环境搭建及数据库增删改查
Introduction to the method of diligently searching for the alliance procedure
Bert use
单通道图片的读入
sqlite交叉編譯動態庫
Leetcode-553. Optimal division
On the normalization of camera rotation interpolation