当前位置:网站首页>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
边栏推荐
- Did you brush the real title of the blue bridge cup over the years? Come here and teach you to counter attack!
- Granularity of blocking of concurrency control
- Pl/sql basic syntax
- DataGrid directly edits and saves "design defects"
- datagrid直接编辑保存“设计缺陷”
- 华为联机对战如何提升玩家匹配成功几率
- Two stage locking protocol for concurrency control
- Win11缺少dll文件怎么办?Win11系统找不到dll文件修复方法
- Pl/sql basic case
- poj 3237 Tree(樹鏈拆分)
猜你喜欢
Efficiency difference between row first and column first traversal of mat data types in opencv
Concurrency control of performance tuning methodology
从零开始实现lmax-Disruptor队列(四)多线程生产者MultiProducerSequencer原理解析
Pl/sql basic case
科技云报道荣膺全球云计算大会“云鼎奖”2013-2022十周年特别贡献奖
Meituan dynamic thread pool practice ideas, open source
多家呼吸机巨头产品近期被一级召回 呼吸机市场仍在增量竞争
Huawei game multimedia service calls the method of shielding the voice of the specified player, and the error code 3010 is returned
Bitbucket installation configuration
MySQL disconnection reports an error MySQL ldb_ exceptions. OperationalError 4031, The client was disconnected by the server
随机推荐
ICMP introduction
Summary of El and JSTL precautions
Poj 3237 Tree (Tree Chain Split)
Implementing Lmax disruptor queue from scratch (IV) principle analysis of multithreaded producer multiproducersequencer
Form artifact
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
Index optimization of performance tuning methodology
如何组织一场实战攻防演练
Storage optimization of performance tuning methodology
MMAP
Getting started with microservices (resttemplate, Eureka, Nacos, feign, gateway)
Implementation technology of recovery
Granularity of blocking of concurrency control
Image editor for their AutoLayout environment
A long's perception
Learning of mall permission module
数博会精彩回顾 | 彰显科研实力,中创算力荣获数字化影响力企业奖
Cross end solutions to improve development efficiency
Talking about MySQL index
Oracle检查点队列–实例崩溃恢复原理剖析