当前位置:网站首页>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 !
边栏推荐
- Lecture 16 of project practice: using the open close principle to realize the commodity price rule engine
- The cooperation between starfish OS and metabell is just the beginning
- 面试题 01.09. 字符串轮转
- 面试题 01.08. 零矩阵
- Opengauss active / standby architecture works with keeplive
- 闻泰科技收购安世半导体剩余股权获得无条件通过
- Data problems can also be found if there is a space at the end of the field value of MySQL query criteria
- Flutter 通话界面UI
- PHP利用某些函数bypass waf探讨
- 面试题 01.07. 旋转矩阵
猜你喜欢
随机推荐
Unity shader introduction Essentials - basic texture
Cross domain requests in nodejs
Distributed | how to import data into dble quickly through the split function of dble
Gossip: an initially perfect FS is as impractical as the first version of the program requiring no bugs
Starfish Os打造的元宇宙生态,跟MetaBell的合作只是开始
2022/07/27 learning notes (Day17) code blocks and internal classes
Knowledge of two-dimensional array
Briefly understand namenode and datanode
Codeforces暑期训练周报(7.21~7.27)
Three basic teaching
JG-数据重置(wd)
Harmonyos 3 was officially released: Hongmeng mobile phones are smooth and safe, and Hongmeng terminals are often used
8000 word explanation of OBSA principle and application practice
spreadsheet 导出 excel表格
Storage practices for high-performance computing scenarios, see here
Huawei's Hubble investment shares in VCSEL chip manufacturer Zonghui Xinguang
Unity Shader入门精要学习——基础纹理
The cooperation between starfish OS and metabell is just the beginning
Gazebo 控制实例
【C语言】文件操作








