当前位置:网站首页>Leetcode simple question check whether all characters appear the same number of times
Leetcode simple question check whether all characters appear the same number of times
2022-07-05 22:03:00 【·Starry Sea】
subject
Give you a string s , If s It's a good character string , Please return true , Otherwise, please return to false .
If s In the all Number of occurrences of characters identical , So we call strings s yes good character string .
Example 1:
Input :s = “abacbc”
Output :true
explain :s The characters that have appeared in are ‘a’,‘b’ and ‘c’ .s All characters appear in 2 Time .
Example 2:
Input :s = “aaabb”
Output :false
explain :s The characters that have appeared in are ‘a’ and ‘b’ .
‘a’ There is 3 Time ,‘b’ There is 2 Time , The two appear different times .
Tips :
1 <= s.length <= 1000
s Only lowercase letters .
source : Power button (LeetCode)
Their thinking
Count the frequency of each character in the string , Then randomly take the frequency of a character as the most contrast , Traverse the frequency table and compare whether the frequencies are consistent .
class Solution:
def areOccurrencesEqual(self, s: str) -> bool:
s=Counter(s)
target=s.popitem()[1]
for i in s.values():
if i!=target:
return False
return True
边栏推荐
- Hysbz 2243 staining (tree chain splitting)
- "Chris Richardson microservices series" uses API gateway to build microservices
- Performance monitoring of database tuning solutions
- AD637 usage notes
- Getting started with microservices (resttemplate, Eureka, Nacos, feign, gateway)
- 多家呼吸机巨头产品近期被一级召回 呼吸机市场仍在增量竞争
- POJ 3237 tree (tree chain splitting)
- How can Huawei online match improve the success rate of player matching
- Form artifact
- [Yugong series] go teaching course 003-ide installation and basic use in July 2022
猜你喜欢
Stored procedures and stored functions
华为云ModelArts文本分类–外卖评论
The Blue Bridge Cup web application development simulation competition is open for the first time! Contestants fast forward!
The American Championship is about to start. Are you ready?
Implementation technology of recovery
Huawei game multimedia service calls the method of shielding the voice of the specified player, and the error code 3010 is returned
Yolov5 training custom data set (pycharm ultra detailed version)
Two stage locking protocol for concurrency control
Experienced inductance manufacturers tell you what makes the inductance noisy. Inductance noise is a common inductance fault. If the used inductance makes noise, you don't have to worry. You just need
Server optimization of performance tuning methodology
随机推荐
An exception occurred in Huawei game multimedia calling the room switching method internal system error Reason:90000017
Oracle检查点队列–实例崩溃恢复原理剖析
database mirroring
Blocking of concurrency control
oracle 控制文件的多路复用
[Yugong series] go teaching course 003-ide installation and basic use in July 2022
EBS Oracle 11g cloning steps (single node)
QML reported an error expected token ";", expected a qualified name ID
Comment développer un plug - in d'applet
Tips for using SecureCRT
从零开始实现lmax-Disruptor队列(四)多线程生产者MultiProducerSequencer原理解析
Analysis and test of ModbusRTU communication protocol
Implementing Lmax disruptor queue from scratch (IV) principle analysis of multithreaded producer multiproducersequencer
极狐公司官方澄清声明
Common interview questions of JVM manufacturers
Poj3414 extensive search
Huawei game multimedia service calls the method of shielding the voice of the specified player, and the error code 3010 is returned
MMAP学习
Pointer parameter passing vs reference parameter passing vs value parameter passing
CA certificate trampled pit