当前位置:网站首页>LeetCode 2351. 第一个出现两次的字母
LeetCode 2351. 第一个出现两次的字母
2022-07-27 23:22:00 【Michael阿明】
1. 题目
给你一个由小写英文字母组成的字符串 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)
链接:https://leetcode.cn/problems/first-letter-to-appear-twice
著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。
2. 解题
- set 存储已出现过的字符
class Solution:
def repeatedCharacter(self, s: str) -> str:
occ = set()
for c in s:
if c not in occ:
occ.add(c)
else:
return c
return ''
32 ms 14.9 MB Python3
我的CSDN博客地址 https://michael.blog.csdn.net/
长按或扫码关注我的公众号(Michael阿明),一起加油、一起学习进步!
边栏推荐
- [game] Nintendo Nintendo switch ultra detailed purchase / use guide and precautions (continuous update according to your own use...)
- Transplant QT system for i.mx6ull development board - cross compile QT code
- Redis cache penetration breakdown and avalanche
- JUC concurrent programming learning
- 2022/07/27 learning notes (Day17) code blocks and internal classes
- 实现ABCD字母递增
- Introduction and configuration of vsftpd
- [C language] file operation
- Gazebo 控制实例
- Support Wu xiongang! Arm Chinese management sent an open letter: shocked and angry at the unwarranted allegations!
猜你喜欢

测试人员需要了解的软件流程

【游戏】任天堂Nintendo Switch超详细购买/使用指南以及注意事项(根据自己使用持续更新中...)

Detailed explanation of retinanet network structure

BSP video tutorial issue 21: easy one key implementation of serial port DMA variable length transceiver, support bare metal and RTOS, including MDK and IAR, which is more convenient than stm32cubemx (

JUC concurrent programming learning

Flutter--密码登录注册界面

Node red interacts with tdengine

Gossip: an initially perfect FS is as impractical as the first version of the program requiring no bugs

HarmonyOS 3正式发布:鸿蒙手机流畅安全,鸿蒙终端常用常新

The cooperation between starfish OS and metabell is just the beginning
随机推荐
开发 Flutter 录音功能的插件
Arm中国夺权大战的背后:“独立”两年,仍难“自主”?
Unknown database ‘xxxxx‘
Focus loss explanation
Gazebo control example
如何解决12,000家中小客户的元器件采购痛点?告别加班!
HarmonyOS 3正式发布:鸿蒙手机流畅安全,鸿蒙终端常用常新
Spreadsheet export excel table
File system mount
Fabric2.4.4 version building process (complete process)
Redis cache penetration breakdown and avalanche
BigDecimal常用API
【游戏】任天堂Nintendo Switch超详细购买/使用指南以及注意事项(根据自己使用持续更新中...)
迅为i.MX6ULL开发板Qt系统移植-交叉编译Qt代码
闻泰科技收购安世半导体剩余股权获得无条件通过
Redefine analysis - release of eventbridge real-time event analysis platform
从功能测试到自动化测试,月薪突破30K+,我的6年测开经验。
ABAP CDs table function introduction and examples
System clock failure of database fault tolerance
3000 words and 11 pictures hard core popular science: what is edge computing? What are the connections and differences with cloud computing?