当前位置:网站首页>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
边栏推荐
- Matlab | app designer · I used Matlab to make a real-time editor of latex formula
- AD637使用筆記
- How can Huawei online match improve the success rate of player matching
- EL与JSTL注意事项汇总
- The Blue Bridge Cup web application development simulation competition is open for the first time! Contestants fast forward!
- datagrid直接编辑保存“设计缺陷”
- Livelocks and deadlocks of concurrency control
- 科技云报道:算力网络,还需跨越几道坎?
- 笔记本电脑蓝牙怎么用来连接耳机
- Oracle checkpoint queue - Analysis of the principle of instance crash recovery
猜你喜欢
How to view Apache log4j 2 remote code execution vulnerability?
Decorator learning 01
AD637使用筆記
装饰器学习01
Server optimization of performance tuning methodology
资深电感厂家告诉你电感什么情况会有噪音电感噪音是比较常见的一种电感故障情况,如果使用的电感出现了噪音大家也不用着急,只需要准确查找分析出什么何原因,其实还是有具体的方法来解决的。作为一家拥有18年品牌
Two stage locking protocol for concurrency control
AD637 usage notes
Implementation technology of recovery
An exception occurred in Huawei game multimedia calling the room switching method internal system error Reason:90000017
随机推荐
How to develop and introduce applet plug-ins
Advantages and disadvantages of the "Chris Richardson microservice series" microservice architecture
华为游戏多媒体调用切换房间方法出现异常Internal system error. Reason:90000017
How can Huawei online match improve the success rate of player matching
The Blue Bridge Cup web application development simulation competition is open for the first time! Contestants fast forward!
A long's perception
每日刷题记录 (十四)
Poj3414 extensive search
Yolov5 training custom data set (pycharm ultra detailed version)
从零开始实现lmax-Disruptor队列(四)多线程生产者MultiProducerSequencer原理解析
Scenario interview: ten questions and ten answers about distributed locks
Blocking of concurrency control
[Yugong series] go teaching course 003-ide installation and basic use in July 2022
The real situation of programmers
poj 3237 Tree(树链拆分)
Win11缺少dll文件怎么办?Win11系统找不到dll文件修复方法
Database recovery strategy
C language knowledge points link
Type of fault
[Yugong series] go teaching course in July 2022 004 go code Notes