当前位置:网站首页>The first letter of leetcode simple question appears twice
The first letter of leetcode simple question appears twice
2022-07-26 19:05:00 【·Starry Sea】
subject
Give you a string of lowercase English letters s , Please find out and return to the first occurrence two The letter of .
Be careful :
If a Of The second time Appearance ratio b Of The second time Appear higher in the string , It is considered as a letter a In the letters b Twice before .
s Contains at least one letter that appears twice .
Example 1:
Input :s = “abccbaacz”
Output :“c”
explain :
Letter ‘a’ In subscript 0 、5 and 6 Appears at .
Letter ‘b’ In subscript 1 and 4 Appears at .
Letter ‘c’ In subscript 2 、3 and 7 Appears at .
Letter ‘z’ In subscript 8 Appears at .
Letter ‘c’ Is the first letter that appears twice , Because of all the letters ,‘c’ The subscript of the second occurrence is the smallest .
Example 2:
Input :s = “abcdd”
Output :“d”
explain :
Only letters ‘d’ Twice , So back ‘d’ .
Tips :
2 <= s.length <= 100
s It's made up of lowercase letters
s Contains at least one repeating letter
source : Power button (LeetCode)
Their thinking
This is a simple character frequency statistics problem , You can start to count the character frequency first. Once you find a qualified character in the statistical process , You can return the result .
class Solution:
def repeatedCharacter(self, s: str) -> str:
d={
}
for i in s:
d[i]=d.get(i,0)+1
if d[i]>1:
return i

边栏推荐
猜你喜欢

FTP协议

LeetCode简单题之装满杯子需要的最短总时长

SSM整-整合配置

SSM integration - functional module and interface testing

Tensor Rt的int8量化原理

Likeshop takeout order system is open source, 100% open source, no encryption

SMMU carding

支持代理直连Oracle数据库,JumpServer堡垒机v2.24.0发布

JS刷题计划——链表

Comparison of advantages and disadvantages between SD NAND and EMMC
随机推荐
VTK (the Visualization Toolkit) loads STL models
Interview summary of some large factories
The pit of mpc5744p reports an error, RTOS cannot be started, and there is a clock source problem
JS刷题计划——数组
当前占位,之后再写
[AUTOSAR RTE] - 1-talk about RTE (run time environment)
Simulated 100 questions and simulated examination of refrigeration and air conditioning equipment operation examination in 2022
议程速递 | 7月27日分论坛议程一览
Arrangement of information security emergency plan
【考研词汇训练营】Day 13 —— reliance,expert,subject,unconscious,photograph,exaggeration,counteract
NFT数字藏品系统开发:“中国旅游日”山西首次发布古建筑数字藏品
Tensor Rt的int8量化原理
MySQL - 函数及约束命令
The United States, Japan and South Korea jointly developed 6G with the intention of anti surpassing, but China has long been prepared
SSM integration configuration
SD NAND与eMMC优劣势对比
2022 welder (elementary) operation certificate examination question bank and simulation examination
File upload and download test point
Write a thesis and read this one
SSM整合-功能模块和接口测试