๋ฌธ์
https://school.programmers.co.kr/learn/courses/30/lessons/142086
ํ์ด
# ํ๋ก๊ทธ๋๋จธ์ค 1๋จ๊ณ - ๊ฐ์ฅ ๊ฐ๊น์ด ๊ฐ์ ๊ธ์
def solution(s):
answer = []
d = dict()
for i in range(len(s)):
if s[i] not in d:
answer.append(-1)
else:
answer.append(i-d[s[i]])
d[s[i]] = i
return answer
print(solution("banana"))
'๐๏ธ Algorithm > โฌ ํ๋ก๊ทธ๋๋จธ์ค' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
โฌ [Programmers] [Python] [Level3] ์ด์ค ์ฐ์ ์์ ํ (0) | 2023.04.11 |
---|---|
โฌ [Programmers] [Python] [Level1] ์์ ์ฐพ๊ธฐ (0) | 2023.04.10 |
โฌ [Programmers] [Python] [Level1] ํธ๋ ํ์ดํธ ๋ํ (0) | 2023.04.10 |
โฌ [Programmers] [Python] [Level1] ์ผ์ด์ฌ (0) | 2023.04.10 |
โฌ [Programmers] [Python] [Level1] ์ด์ํ ๋ฌธ์ ๋ง๋ค๊ธฐ (0) | 2023.04.10 |