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

边栏推荐
- Stored procedures and stored functions
- Getting started with microservices (resttemplate, Eureka, Nacos, feign, gateway)
- Two stage locking protocol for concurrency control
- Implementing Lmax disruptor queue from scratch (IV) principle analysis of multithreaded producer multiproducersequencer
- oracle 控制文件的多路复用
- HYSBZ 2243 染色 (树链拆分)
- 从零开始实现lmax-Disruptor队列(四)多线程生产者MultiProducerSequencer原理解析
- Poj3414 extensive search
- CA certificate trampled pit
- POJ 3237 tree (tree chain splitting)
猜你喜欢

Database recovery strategy

Efficiency difference between row first and column first traversal of mat data types in opencv

Server optimization of performance tuning methodology

A number of ventilator giants' products have been recalled recently, and the ventilator market is still in incremental competition

Business learning of mall order module

MMAP learning

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

Yolov5 training custom data set (pycharm ultra detailed version)

Daily question brushing record (XIV)
随机推荐
Poj3414广泛搜索
Basic grammar of interview (Part 1)
Detailed explanation of memset() function usage
Implementation technology of recovery
AD637使用筆記
CA certificate trampled pit
Drawing HSV color wheel with MATLAB
Business learning of mall commodity module
Ad637 notes d'utilisation
poj 3237 Tree(树链拆分)
The solution to the problem that Oracle hugepages are not used, causing the server to be too laggy
资深电感厂家告诉你电感什么情况会有噪音电感噪音是比较常见的一种电感故障情况,如果使用的电感出现了噪音大家也不用着急,只需要准确查找分析出什么何原因,其实还是有具体的方法来解决的。作为一家拥有18年品牌
Matlab | app designer · I used Matlab to make a real-time editor of latex formula
了解 Android Kotlin 中 DataStore 的基本概念以及为什么应该停止在 Android 中使用 SharedPreferences
如何开发引入小程序插件
Common interview questions of JVM manufacturers
[Yugong series] go teaching course in July 2022 004 go code Notes
MATLAB | App Designer·我用MATLAB制作了一款LATEX公式实时编辑器
Business learning of mall order module
如何组织一场实战攻防演练