본문 바로가기
Algorithm

[프로그래머스] 전화번호 목록 파이썬 Hash

by YGSEO 2021. 3. 11.
728x90

테스트 케이스가 바뀌기도 했고

해쉬 카테고리인테 해쉬가 어떻게 쓰이는지 궁금하던 찰나 발견한 블로그

 

파이썬 의 dictionary 자료형이 hash table 이다.

def solution(phone_book):
    answer = True
    hash_map = {}
    
    # 등장한 숫자들을 count 딕셔너리로 만듦
    for phone_number in phone_book:
        hash_map[phone_number] = 1
        
    # 다시 숫자들을 꺼낸뒤
    for phone_number in phone_book:
        temp = ""
        for number in phone_number: #숫자 하나씩 뜯어보기
            temp += number
            #딕셔너리 키로 같은게 있지만! 전체 숫자는 다른 경우!
            if temp in hash_map and temp != phone_number:
                answer = False
                
    print(hash_map)
    return answer

 

 

 

파이썬 해쉬 설명:

comdoc.tistory.com/entry/17-%ED%95%B4%EC%8B%B1hashing-%ED%8C%8C%EC%9D%B4%EC%8D%AC

 

답안 출처:

huidea.tistory.com/6

728x90

'Algorithm' 카테고리의 다른 글

[프로그래머스] 카펫 파이썬  (0) 2021.03.12
[프로그래머스] H-index 파이썬  (0) 2021.03.11
[프로그래머스] 가장 큰 수 파이썬  (0) 2021.03.11
[프로그래머스] 소수 찾기 파이썬  (0) 2021.03.10
[Python] Heap  (0) 2021.03.10

댓글