当前位置:网站首页>Leetcode 2351. the first letter that appears twice
Leetcode 2351. the first letter that appears twice
2022-07-28 01:35:00 【Michael Amin】
List of articles
1. subject
Give you a string of lowercase English letters s , Please find out and return to first appear 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)
link :https://leetcode.cn/problems/first-letter-to-appear-twice
Copyright belongs to the network . For commercial reprint, please contact the official authority , Non-commercial reprint please indicate the source .
2. Problem solving
- set Store characters that have appeared
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
my CSDN Blog address https://michael.blog.csdn.net/
Long click or sweep code pay attention to my official account (Michael amin ), Come on together 、 Learn together !
边栏推荐
- 软件测试面试题:如何发现数据库的相关问题?
- Shenzhen Huaqiang announced that it plans to invest no more than 20million yuan in BYD semiconductor
- Rviz uses arbotix to control robot motion
- Rviz 使用Arbotix控制机器人运动
- idea常用的快捷键汇总
- How the test architects of bat factories interpret various disputes of the test platform
- 数仓搭建——DWS层
- EWM收货ECC交货单校验逻辑问题
- 逻辑回归原理
- How to make digital retail undertake the development task of the era of traffic and retention may be the key
猜你喜欢

How to calculate the profit and loss of spot Silver

From functional testing to automated testing, my monthly salary has exceeded 30k+, and I have 6 years of testing experience.

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

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

Cesium add dynamic pop-up

Summary of common shortcut keys in idea

Redefine analysis - release of eventbridge real-time event analysis platform

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

华为“天才少年”稚晖君又出新作,从零开始造“客制化”智能键盘

LeetCode 2347. 最好的扑克手牌
随机推荐
spreadsheet 导出 excel表格
内容bypass分享
国产NB-IoT芯片厂商芯翼信息科技获2亿元A+轮融资
如何让数字零售承接起流量时代和留量时代的发展重任,或许才是关键所在
How to solve the pain points of 12000 small and medium-sized customers' component procurement? Say goodbye to overtime!
HarmonyOS 3正式发布:鸿蒙手机流畅安全,鸿蒙终端常用常新
Anfulai embedded weekly report no. 275: 2022.07.18--2022.07.24
Byte monthly salary 28K, share a wave of my automation testing experience
闻泰科技收购安世半导体剩余股权获得无条件通过
Wu xiongang sent an internal letter: arm's allegations are unwarranted, and no damage is allowed to the existing achievements!
Thoroughly understand kubernetes scheduling framework and plug-ins
8000字讲透OBSA原理与应用实践
Transplant QT system for i.mx6ull development board - cross compile QT code
6月19日上会,中芯国际或创造国内最快上市记录!
伦敦银开盘时间知多少
梳理 SQL 性能优化,收藏经典!
Lua get started quickly
“蔚来杯“2022牛客暑期多校训练营3 补题题解(A、C、J)
I want to get 20K after 3 years of experience, but I haven't got it for half a month?
2022/07/27 学习笔记 (day17) 代码块和内部类