当前位置:网站首页>Leetcode 1189. Maximum number of balloons (special character count)
Leetcode 1189. Maximum number of balloons (special character count)
2022-07-03 19:19:00 【wwxy261】

No need to simulate once and for all , Directly use mathematics to calculate the number of balloons that can be spelled out ,Python How to write it :
class Solution:
def maxNumberOfBalloons(self, text: str) -> int:
cnt = Counter(ch for ch in text if ch in "balon")
cnt['l'] //= 2
cnt['o'] //= 2
return min(cnt.values()) if len(cnt) == 5 else 0C++ How to write it , Save a space , Store only the strings you need
class Solution {
public:
int maxNumberOfBalloons(string text) {
vector<int> cnt(5);
for (auto & ch : text) {
if (ch == 'b') {
cnt[0]++;
} else if (ch == 'a') {
cnt[1]++;
} else if (ch == 'l') {
cnt[2]++;
} else if (ch == 'o') {
cnt[3]++;
} else if (ch == 'n') {
cnt[4]++;
}
}
cnt[2] /= 2;
cnt[3] /= 2;
return *min_element(cnt.begin(), cnt.end());
}
};
边栏推荐
- Sentinel source code analysis part I sentinel overview
- Summary of learning materials and notes of Zhang Fei's actual combat electronics 1-31
- 第一章:求n的阶乘n!
- Flutter网络和数据存储框架搭建 -b1
- EGO Planner代码解析bspline_optimizer部分(1)
- Web Security (VII) specific process of authentication with session cookie scheme
- Free year-end report summary template Welfare Collection
- Compared with 4G, what are the advantages of 5g to meet the technical requirements of industry 4.0
- Scrape crawler framework
- 第一章:递归求n的阶乘n!
猜你喜欢
![[optics] vortex generation based on MATLAB [including Matlab source code 1927]](/img/9b/b7f462e2ecbff0cee35e7de5c80cf7.jpg)
[optics] vortex generation based on MATLAB [including Matlab source code 1927]

Think of new ways

OSPF - detailed explanation of stub area and full stub area

Php based campus lost and found platform (automatic matching push)

Record: writing MySQL commands

Flume learning notes

EGO Planner代码解析bspline_optimizer部分(2)

Using the visualization results, click to appear the corresponding sentence

This Chinese numpy quick look-up table is too easy!

These problems should be paid attention to in the production of enterprise promotional videos
随机推荐
Go home early today
__ Weak and__ The difference between blocks
Merge K ascending linked lists
论文阅读 GloDyNE Global Topology Preserving Dynamic Network Embedding
How to build an efficient information warehouse
Record: install MySQL on ubuntu18.04
Sqlalchemy - subquery in a where clause - Sqlalchemy - subquery in a where clause
第一章:求同吗小数和s(d, n)
Record: writing MySQL commands
[academic related] how to find the innovation of top papers? Chinese universities won the CVPR Best Student Thesis Award for the first time
[optics] dielectric constant calculation based on MATLAB [including Matlab source code 1926]
A green plug-in that allows you to stay focused, live and work hard
Dart JSON编码器和解码器剖析
交叉编译Opencv带Contrib
SSM integration - joint debugging of front and rear protocols (list function, add function, add function status processing, modify function, delete function)
Zhang Fei hardware 90 day learning notes - personal record of day 3, please see my personal profile / homepage for the complete
【疾病识别】基于matlab GUI机器视觉肺癌检测系统【含Matlab源码 1922期】
Differential constrained SPFA
Next spread
[proteus simulation] a simple encrypted electronic password lock designed with 24C04 and 1602LCD