当前位置:网站首页>LeetCode简单题之第一个出现两次的字母
LeetCode简单题之第一个出现两次的字母
2022-07-26 18:00:00 【·星辰大海】
题目
给你一个由小写英文字母组成的字符串 s ,请你找出并返回第一个出现 两次 的字母。
注意:
如果 a 的 第二次 出现比 b 的 第二次 出现在字符串中的位置更靠前,则认为字母 a 在字母 b 之前出现两次。
s 包含至少一个出现两次的字母。
示例 1:
输入:s = “abccbaacz”
输出:“c”
解释:
字母 ‘a’ 在下标 0 、5 和 6 处出现。
字母 ‘b’ 在下标 1 和 4 处出现。
字母 ‘c’ 在下标 2 、3 和 7 处出现。
字母 ‘z’ 在下标 8 处出现。
字母 ‘c’ 是第一个出现两次的字母,因为在所有字母中,‘c’ 第二次出现的下标是最小的。
示例 2:
输入:s = “abcdd”
输出:“d”
解释:
只有字母 ‘d’ 出现两次,所以返回 ‘d’ 。
提示:
2 <= s.length <= 100
s 由小写英文字母组成
s 包含至少一个重复字母
来源:力扣(LeetCode)
解题思路
这是一道简单的字符频率统计题,可以先着手进行字符频率的统计在统计的过程中一旦发现有符合条件的字符出现,即可返回结果。
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

边栏推荐
- SSM整-整合配置
- Racher deploys kubernetes cluster
- Redis core principles
- rancher部署kubernetes集群
- How to become an excellent test / development programmer? Focus on planning and then move
- 【考研词汇训练营】Day 14 —— panini,predict,access,apologize,sense,transport,aggregation
- 2022G1工业锅炉司炉上岗证题库及模拟考试
- 我酷故我在
- JS question brushing plan - array
- 骚操作:巧用MySQL主从复制延迟拯救误删数据
猜你喜欢

分布式事务-seata

如何成为一名优秀的测试/开发程序员?专注谋定而后动......

2022G1工业锅炉司炉上岗证题库及模拟考试

VPC nat (Sant, nant) experiment

Database expansion can also be so smooth, MySQL 100 billion level data production environment expansion practice

MySQL学习笔记-2.如何提高sql语句的查询性能

Interview summary of some large factories

神经网络学习(2)前言介绍二

Simulated 100 questions and simulated examination of refrigeration and air conditioning equipment operation examination in 2022

SSM整合-功能模块和接口测试
随机推荐
Pyqt5 rapid development and practice 3.5 menu bar and toolbar
MPLS experiment
2022 chemical automation control instrument test question simulation test platform operation
如何成为一名优秀的测试/开发程序员?专注谋定而后动......
JS uses readLine to realize terminal input data
【在 Kotlin 中添加条件行为】
JS刷题计划——数组
MySQL日志介绍
Lombok common notes
Complete MySQL database commands
Likeshop takeout order system is open source, 100% open source, no encryption
神经网络学习(2)前言介绍二
[add conditional behavior in kotlin]
Learn UML system modeling from me
Sentinel 隔离与降级
CTO will teach you: how to take over his project when a technician suddenly leaves
Lombok常用注解
[yuntu said] issue 246 digital asset chain - your God of digital asset property protection!
Neural network learning (2) introduction 2
Excellent JSON processing tool