当前位置:网站首页>LeetCode_ 6124_ The first letter that appears twice
LeetCode_ 6124_ The first letter that appears twice
2022-07-24 23:54:00 【Fitz1318】
Topic link
Title Description
Give you a string of lowercase English letters s , Please find out and return to the first occurrence 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 <= 100sIt's made up of lowercase letterssContains at least one repeating letter
Their thinking
HashSet To do it
AC Code
class Solution {
public char repeatedCharacter(String s) {
HashSet<Character> set = new HashSet<>();
for (int i = 0; i < s.length(); i++) {
char c = s.charAt(i);
if (set.contains(c)) {
return c;
} else {
set.add(c);
}
}
return ' ';
}
}
边栏推荐
- 代码覆盖率
- How to put long links into Excel
- Mandatory interview questions: 1. shallow copy and deep copy_ Deep copy
- Convex optimization Basics
- HTB-Aragog
- Live broadcast preview | online seminar on open source security governance models and tools
- codeforces round #805 ABCDEFG
- Effect evaluation of generative countermeasure network
- Pointers and arrays
- [nuxt 3] (x) runtime configuration
猜你喜欢

Power consumption of chip

Bug summary

Notes of Teacher Li Hongyi's 2020 in-depth learning series 4

Convex optimization Basics

QT learning - using database singleton to complete login matching + registration function

91. (leaflet chapter) leaflet situation plotting - offensive direction drawing

Notes of Teacher Li Hongyi's 2020 in-depth learning series 9

Pit record: typeerror:'module'object is not callable

Multithreading & high concurrency (the latest in the whole network: interview questions + map + Notes) the interviewer is calm

你还在使用System.currentTimeMillis()?来看看StopWatch吧
随机推荐
Browser cache
Simple message queue implementation nodejs + redis =mq
Sql文件导入数据库-保姆级教程
Mandatory interview questions: 1. shallow copy and deep copy_ Shallow copy
Entity service is an anti pattern
Processing PDF and JPG files in VB6
Code coverage
Regular expression learning
Are you still using system. Currenttimemillis()? Take a look at stopwatch
Yaml writing rules and comparison between yaml and JSON
First experience of flask
How to propose effective solutions for high-end products? (1 methodology + 2 cases + 1 List)
Notes of Teacher Li Hongyi's 2020 in-depth learning series 8
Use of serial queues
MATLAB basic grammar (II)
ShardingSphere-数据库分库分表简介
Vite3.0 has been released, can you still roll it (list of new features)
In pgplsql: = and=
50 places are limited to open | with the news of oceanbase's annual press conference coming!
谢振东:公共交通行业数字化转型升级的探索与实践