python-algorithm
leetcode2351. First Letter to Appear Twice
무적김두칠
2023. 1. 11. 11:55
https://leetcode.com/problems/first-letter-to-appear-twice/description/
First Letter to Appear Twice - LeetCode
First Letter to Appear Twice - Given a string s consisting of lowercase English letters, return the first letter to appear twice. Note: * A letter a appears twice before another letter b if the second occurrence of a is before the second occurrence of b. *
leetcode.com
1
2
3
4
5
6
7
8
|
class Solution:
def repeatedCharacter(self, s: str) -> str:
string_list = []
for i in s:
if i not in string_list:
string_list.append(i)
else:
return i
|
cs |
반응형