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

边栏推荐
- Codeforces 12D ball tree array simulation 3 sorting elements
- 微服務鏈路風險分析
- Summary of concurrency control
- Win11缺少dll文件怎么办?Win11系统找不到dll文件修复方法
- Recovery technology with checkpoints
- Dbeaver executes multiple insert into error processing at the same time
- 资深电感厂家告诉你电感什么情况会有噪音电感噪音是比较常见的一种电感故障情况,如果使用的电感出现了噪音大家也不用着急,只需要准确查找分析出什么何原因,其实还是有具体的方法来解决的。作为一家拥有18年品牌
- 【愚公系列】2022年7月 Go教学课程 003-IDE的安装和基本使用
- 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
- Huawei game multimedia service calls the method of shielding the voice of the specified player, and the error code 3010 is returned
猜你喜欢

Kingbasees v8r3 cluster maintenance case -- online addition of standby database management node

A trip to Suzhou during the Dragon Boat Festival holiday

Overview of concurrency control

极狐公司官方澄清声明

The Blue Bridge Cup web application development simulation competition is open for the first time! Contestants fast forward!

EBS Oracle 11g 克隆步骤(单节点)

装饰器学习01

华为云ModelArts文本分类–外卖评论

Defect detection - Halcon surface scratch detection

An exception occurred in Huawei game multimedia calling the room switching method internal system error Reason:90000017
随机推荐
了解 Android Kotlin 中 DataStore 的基本概念以及为什么应该停止在 Android 中使用 SharedPreferences
Pl/sql basic case
从零开始实现lmax-Disruptor队列(四)多线程生产者MultiProducerSequencer原理解析
阿龙的感悟
HDU 4391 paint the wall segment tree (water
Business learning of mall commodity module
Oracle triggers
AD637 usage notes
Analyse des risques liés aux liaisons de microservices
Ad637 notes d'utilisation
深信服X计划-网络协议基础 DNS
Concurrency control of performance tuning methodology
A number of ventilator giants' products have been recalled recently, and the ventilator market is still in incremental competition
Summarize the reasons for 2XX, 3xx, 4xx, 5xx status codes
Decorator learning 01
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
Oracle检查点队列–实例崩溃恢复原理剖析
Countdown to 92 days, the strategy for the provincial preparation of the Blue Bridge Cup is coming~
EL与JSTL注意事项汇总
微服務鏈路風險分析