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

边栏推荐
- 华为游戏多媒体调用切换房间方法出现异常Internal system error. Reason:90000017
- HDU 4391 paint the wall segment tree (water
- Efficiency difference between row first and column first traversal of mat data types in opencv
- Summarize the reasons for 2XX, 3xx, 4xx, 5xx status codes
- [Yugong series] go teaching course in July 2022 004 go code Notes
- MMAP learning
- Lightweight dynamic monitorable thread pool based on configuration center - dynamictp
- 微服务入门(RestTemplate、Eureka、Nacos、Feign、Gateway)
- Implementing Lmax disruptor queue from scratch (IV) principle analysis of multithreaded producer multiproducersequencer
- Dbeaver executes multiple insert into error processing at the same time
猜你喜欢

Create a virtual machine on VMware (system not installed)

PyGame practical project: write Snake games with 300 lines of code

Defect detection - Halcon surface scratch detection

Summary of concurrency control

An exception occurred in Huawei game multimedia calling the room switching method internal system error Reason:90000017

Blocking protocol for concurrency control

Official clarification statement of Jihu company

笔记本电脑蓝牙怎么用来连接耳机

科技云报道荣膺全球云计算大会“云鼎奖”2013-2022十周年特别贡献奖

装饰器学习01
随机推荐
了解 Android Kotlin 中 DataStore 的基本概念以及为什么应该停止在 Android 中使用 SharedPreferences
MySQL连接断开报错MySQLdb._exceptions.OperationalError 4031, The client was disconnected by the server
Overview of database recovery
poj 3237 Tree(树链拆分)
matlab绘制hsv色轮图
Pl/sql basic case
Defect detection - Halcon surface scratch detection
CA certificate trampled pit
Codeforces 12D Ball 树形阵列模拟3排序元素
Analyse des risques liés aux liaisons de microservices
NET中小型企业项目开发框架系列(一个)
资深电感厂家告诉你电感什么情况会有噪音电感噪音是比较常见的一种电感故障情况,如果使用的电感出现了噪音大家也不用着急,只需要准确查找分析出什么何原因,其实还是有具体的方法来解决的。作为一家拥有18年品牌
Getting started with microservices (resttemplate, Eureka, Nacos, feign, gateway)
Learning of mall permission module
Win11缺少dll文件怎么办?Win11系统找不到dll文件修复方法
U盘的文件无法删除文件怎么办?Win11无法删除U盘文件解决教程
Regular expressions and re Libraries
极狐公司官方澄清声明
Blocking of concurrency control
深信服X计划-网络协议基础 DNS