DESCRIPTION:
Find the first character that repeats in a String and return that character.
first_dup('tweet') => 't'
first_dup('like') => None
This is not the same as finding the character that repeats first. In that case, an input of 'tweet' would yield 'e'.
Another example:
In 'translator' you should return 't', not 'a'.
v v
translator
^ ^
While second 'a' appears before second 't', the first 't' is before the first 'a'.
def first_dup(s):
for i in range(len(s)):
if s[i] in s[i+1:]:
return s[i]
'알고리즘 문제 > CodeWar' 카테고리의 다른 글
Collatz (0) | 2022.11.15 |
---|---|
Is Integer Array? (0) | 2022.11.15 |
Row Of The Odd Triangle (0) | 2022.11.15 |
Find the Mine! (0) | 2022.11.14 |
Sequences and Series (0) | 2022.11.14 |