当前位置:网站首页>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

边栏推荐
- Kingbasees v8r3 cluster maintenance case -- online addition of standby database management node
- PIP install beatifulsoup4 installation failed
- Drawing HSV color wheel with MATLAB
- Form artifact
- K210 learning notes (IV) k210 runs multiple models at the same time
- Installation of VMware Workstation
- 阿龙的感悟
- Daily question brushing record (XIV)
- 每日刷题记录 (十四)
- Granularity of blocking of concurrency control
猜你喜欢

Daily question brushing record (XIV)

Getting started with microservices (resttemplate, Eureka, Nacos, feign, gateway)

Talking about MySQL index

Matlab | app designer · I used Matlab to make a real-time editor of latex formula

Overview of concurrency control

How to use tensorflow2 for cat and dog classification and recognition

Huawei cloud modelarts text classification - takeout comments
![[Yugong series] go teaching course 003-ide installation and basic use in July 2022](/img/9d/7d01bc1daa61f6545f619b6746f8bb.png)
[Yugong series] go teaching course 003-ide installation and basic use in July 2022

元宇宙中的三大“派系”

Oracle检查点队列–实例崩溃恢复原理剖析
随机推荐
QML reported an error expected token ";", expected a qualified name ID
How to develop and introduce applet plug-ins
Poj3414 extensive search
Business learning of mall order module
Storage optimization of performance tuning methodology
Web3为互联网带来了哪些改变?
Form artifact
[Yugong series] go teaching course 003-ide installation and basic use in July 2022
Cross end solutions to improve development efficiency
Robot operation mechanism
How to organize an actual attack and defense drill
SecureCRT使用提示
1.3 years of work experience, double non naked resignation agency face-to-face experience [already employed]
POJ 3237 tree (tree chain splitting)
初级软件测试必问面试题
A number of ventilator giants' products have been recalled recently, and the ventilator market is still in incremental competition
AD637 usage notes
Database recovery strategy
Meituan dynamic thread pool practice ideas, open source
Implementing Lmax disruptor queue from scratch (IV) principle analysis of multithreaded producer multiproducersequencer