当前位置:网站首页>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 !
边栏推荐
- String
- 软件测试面试题:think_time的作用是什么?
- Monitor mouse sideslip (adapt to mobile terminal)
- C language main function transfer parameters
- Lecture 16 of project practice: using the open close principle to realize the commodity price rule engine
- 容器网络硬核技术内幕 (7) 大海航行靠舵手
- Distributed | how to import data into dble quickly through the split function of dble
- Icml2022 | online decision transformer
- 杂谈:一份最初就非常完善的FS跟第一版程序就要求没bug一样不切实际
- Gazebo 控制实例
猜你喜欢

LeetCode 2341. 数组能形成多少数对

Can anime characters become "real people"? Paddegan helps you find the TA of "tear man"

Lua advanced

“蔚来杯“2022牛客暑期多校训练营3 补题题解(A、C、J)

工具函数:把一个工作区中非空字段值付给另一个工作区相同字段

Fabric2.4.4 version building process (complete process)

Unity Shader入门精要学习——基础纹理

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

梳理 SQL 性能优化,收藏经典!

Software process that testers need to know
随机推荐
8000字讲透OBSA原理与应用实践
Fabric2.4.4 version building process (complete process)
Anfulai embedded weekly report no. 275: 2022.07.18--2022.07.24
Huami technology "Huangshan No.2" release: AI performance is improved by 7 times, and power consumption is reduced by 50%!
JG-数据重置(wd)
工具函数:把一个工作区中非空字段值付给另一个工作区相同字段
Lua进阶
MySQL JPA support for JSON type data in database
"Wei Lai Cup" 2022 Niuke summer multi school training camp 3 supplementary problem solution (a, C, J)
URDF integrated gazebo
吴雄昂发内部信:Arm的指控是莫须有的,现有成果不允许有任何损害!
Introduction and configuration of vsftpd
Shutter -- password login registration interface
Shenzhen Huaqiang announced that it plans to invest no more than 20million yuan in BYD semiconductor
Standing at the crossroads of digital retail transformation, we need to look at it from a new perspective
《安富莱嵌入式周报》第275期:2022.07.18--2022.07.24
C language main function transfer parameters
How to calculate the profit and loss of spot Silver
The cooperation between starfish OS and metabell is just the beginning
Monitor mouse sideslip (adapt to mobile terminal)