当前位置:网站首页>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 !
边栏推荐
- Learn how Baidu PaddlePaddle easydl realizes automatic animal recognition in aquarium
- 闻泰科技收购安世半导体剩余股权获得无条件通过
- The cooperation between starfish OS and metabell is just the beginning
- Count the number of given strings in a string
- Codeforces summer training weekly (7.14~7.20)
- Rviz uses arbotix to control robot motion
- Baidu PaddlePaddle easydl: when AI enters the factory, "small bearing" can also turn "big industry"
- 2022/07/27 学习笔记 (day17) 代码块和内部类
- Insider of container network hard core technology (7) sailing on the sea depends on the helmsman
- 8000 word explanation of OBSA principle and application practice
猜你喜欢

同心向前,Google Play 十周年啦!

How to calculate the profit and loss of spot Silver

Byte monthly salary 28K, share a wave of my automation testing experience

idea常用的快捷键汇总

Fabric2.4.4 version building process (complete process)

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

BSP视频教程第21期:轻松一键实现串口DMA不定长收发,支持裸机和RTOS,含MDK和IAR两种玩法,比STM32CubeMX还方便(2022-07-24)

开发 Flutter 录音功能的插件

PHP利用某些函数bypass waf探讨

【C语言】文件操作
随机推荐
Unity Shader入门精要学习——基础纹理
EWM receiving ECC delivery note verification logic problem
Lua进阶
Xinyi information technology, a domestic NB IOT chip manufacturer, received 200million yuan of a+ round financing
JG-数据重置(wd)
LeetCode 2341. 数组能形成多少数对
比亚迪半导体完成8亿元A+轮融资:30家知名投资机构入局,估值已达102亿元!
The understanding of domain adaptation in transfer learning and the introduction of three technologies
吴雄昂发内部信:Arm的指控是莫须有的,现有成果不允许有任何损害!
Huami technology "Huangshan No.2" release: AI performance is improved by 7 times, and power consumption is reduced by 50%!
EWM收货ECC交货单校验逻辑问题
登录功能实现
彻底搞懂kubernetes调度框架与插件
idea常用的快捷键汇总
华为旗下哈勃投资入股VCSEL芯片厂商纵慧芯光
字节月薪28K,分享一波我的自动化测试经验....
Wentai technology acquired the remaining equity of ANSYS semiconductor and obtained unconditional approval
URDF integrated gazebo
【C语言】文件操作
Knowledge of two-dimensional array