当前位置:网站首页>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());
}
};
边栏推荐
- Record: install MySQL on ubuntu18.04
- Summary of 90 day learning materials and notes of Zhang Fei's actual electronic hardware engineer
- Luogu-p1107 [bjwc2008] Lei Tao's kitten
- 第一章:简化同码小数和s(d, n)
- Streaming media server (16) -- figure out the difference between live broadcast and on-demand
- QT -- qfileinfo file information reading
- FBI warning: some people use AI to disguise themselves as others for remote interview
- 【数学建模】基于matlab船舶三自由度MMG模型【含Matlab源码 1925期】
- 【光学】基于matlab涡旋光产生【含Matlab源码 1927期】
- Floating source code comment (38) parallel job processor
猜你喜欢
![Free hand account sharing in September - [cream Nebula]](/img/4f/fec31778a56886585e35be87885452.jpg)
Free hand account sharing in September - [cream Nebula]

The necessity of lean production and management in sheet metal industry

Octopus online ecological chain tour Atocha protocol received near grant worth $50000

第一章:三位阶乘和数,图形点扫描

第一章:喝汽水,阶梯电费计算,阶梯电费计算函数,个人所税,求解平方根不等式,简化求解平方根不等式,求解调和级数不等式,解不等式:d<1+1/2-1/3+1/4+1/5-1/6+..士1/n

Day_ 18 IO stream system

Common text labels

第一章:拓广同码小数和s(d, n)

FBI警告:有人利用AI换脸冒充他人身份进行远程面试

Foundation of ActiveMQ
随机推荐
Buuctf's different flags and simplerev
[free sharing] kotalog diary2022 plan electronic manual ledger
A green plug-in that allows you to stay focused, live and work hard
Think of new ways
[optics] vortex generation based on MATLAB [including Matlab source code 1927]
Octopus online ecological chain tour Atocha protocol received near grant worth $50000
Free sharing | linefriends hand account inner page | horizontal grid | not for sale
东数西算拉动千亿产业,敢啃“硬骨头”的存储厂商才更有机会
If the warehouse management communication is not in place, what problems will occur?
Yolov3 network model building
第二章:求a,b的最大公约与最小公倍数经典求解,求a,b的最大公约与最小公倍数常规求解,求n个正整数的的最大公约与最小公倍数
Bad mentality leads to different results
The earliest record
第一章:求所有阶乘和数,大奖赛现场统分程序设计,三位阶乘和数,图形点扫描,递归求n的阶乘n!,求n的阶乘n!,舍罕王失算
Compared with 4G, what are the advantages of 5g to meet the technical requirements of industry 4.0
Driveseg: dynamic driving scene segmentation data set
Zhang Fei hardware 90 day learning notes - personal records on day 2, please see my personal profile / homepage for the complete
Pecan — @expose()
Summary of learning materials and notes of Zhang Fei's actual combat electronics 1-31
TFs and SVN [closed] - TFs vs SVN [closed]