Programmers/프로그래머스-외톨이 알파벳-Python

cosmos·2023년 3월 10일
0
post-thumbnail

문제

코드

def solution(input_string: str) -> str:
    dict = {}
    
    for index, alpa in enumerate(input_string):
        if alpa not in dict:
            dict[alpa] = 1
        else:
            if input_string[index-1] != alpa:
                dict[alpa] += 1
    
    l = [key for key, value in dict.items() if value >= 2]
    
    return ''.join(map(str, sorted(l))) if l else 'N'

결과

출처 & 깃허브

프로그래머스
github

0개의 댓글