[Python][프로그래머스][Level2] 전화번호 목록

[Python][프로그래머스][Level2] 전화번호 목록

코드

def solution(phone_book):
    book=dict()
    for number in sorted(phone_book):
        for num in range(1,len(number)+1):
            if number[:num] in book:
                return False
        book[number]=number
    return True

짧은 전화번호 부터 dictionary에 접두사가 있는지 확인한 후에

dictionary에 저장했다.

모든 for 문을 통과하면 True이다.

Discussion and feedback