STUDY/Algorithm

[프로그래머스] LEVEL2 전화번호목록,python3, 해시

sinawi95 2019. 11. 13. 10:51
728x90

def solution(phone_book):
    answer = True
    stack=[]
    index=0
    len_pb=len(phone_book)
    while index!=len_pb:
        stack=phone_book.pop()
        len_st=len(stack)
        for num in phone_book:
            len_num=len(num)
            if len_st>len_num:
                if num==stack[:len_num]:
                    return False
            else:
                if num[:len_st]==stack:
                    return False
        index+=1
    return answer

쉽게 끝냈다