๋ฌธ์
https://school.programmers.co.kr/learn/courses/30/lessons/42577
ํ์ด
# ํ๋ก๊ทธ๋๋จธ์ค 2๋จ๊ณ - ์ ํ๋ฒํธ ๋ชฉ๋ก
def solution(phone_book):
hash_map = {}
for phone_number in phone_book:
hash_map[phone_number] = 1
for phone_number in phone_book:
s = ""
for number in phone_number:
s += number
if s in hash_map and s != phone_number:
return False
return True
print(solution(["123","456","789"]))
์ด๋ฒ ๋ฌธ์ ๋ Hash Map ์ ์ด์ฉํด์ ํ์๋ค. HashTable์ ์๊ฐ ๋ณต์ก๋๋ O(1)์ผ๋ก ํ์ ์๊ฐ์ด 1์ด๋ค.
phone_book์ ๊ธธ์ด๊ฐ 100๋ง์ธ ๋งํผ ์๊ฐ๋ณต์ก๋๋ฅผ ์๊ฐํด์ ํ์ดํ ํ๋ ๋ฌธ์ ์๋ค.