Skip to content

Commit bfb3459

Browse files
zaqquumMingguriguri
authored andcommitted
[PGS]#42577. 전화번호 목록/lv2/실패
https://school.programmers.co.kr/learn/courses/30/lessons/42577
1 parent f0bde0d commit bfb3459

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

Hongjoo/lv2/전화번호목록.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
"""
2+
https://school.programmers.co.kr/learn/courses/30/lessons/42577
3+
"""
4+
5+
def solution(phone_book):
6+
answer = True
7+
#1. 글자수로 정렬하기
8+
phone_book = sorted(phone_book , key = lambda x : (len(x)))
9+
#2. key = 전번인 해쉬맵 생성
10+
hash_map = {}
11+
for phone in phone_book :
12+
hash_map[phone] = 1
13+
#3. hashmap에 접두어 비교하기
14+
for phone in phone_book :
15+
tmp = ""
16+
# 접두어 한 글자씩 추가해서 hasp_map의 key들 중에 같은게 있는지 확인
17+
for n in phone :
18+
tmp += n
19+
if tmp in hash_map and tmp!= phone :
20+
answer = False
21+
22+
23+
24+
25+
26+
return answer

0 commit comments

Comments
 (0)