Programmers

[Programmers / Python 풀이] 가장 가까운 같은 글자

Hoo_Dev 2022. 12. 22. 21:11
def solution(s):
    answer = []
    for i in range(len(s)):
        max_dist = 100000
        for j in range(i):
            if s[j] == s[i]:
                a = i-j
                if a < max_dist:
                    max_dist = a
        if max_dist == 100000:
            answer.append(-1)
        else:
            answer.append(max_dist)
    return answer