728x90
😄 아이디어
1. _!len_list!_리스트로 접두사로 비교될 길이 저장 👉 0번째 길이와 같은 값들은 우선 저장
2. _!len_list!_의 길이만큼 잘라 _!dt!_변수에 _!key!_보관 👉 동일한_!key!_에 값이 있으면 예외처리
3. 예외처리된 것이 없으면 현재 값 _!dt!_보관 & 현재 값 길이 대조 후_!len_list!_에 보관
def solution(phone_book):
answer = True
dt = {}
phone_book.sort(key = len)
len_list = [len(phone_book[0])]
for i, val in enumerate(phone_book):
if len(val) == len_list[0]:
dt[val] = dt.get(val, 0) + 1
continue
for l in len_list:
key = val[0:l]
if dt.get(key, 0) + 1 > 1:
return False
dt[val] = 1
if len_list[-1] != len(val):
len_list.append(len(val))
return answer
✔️링크: https://school.programmers.co.kr/learn/courses/30/lessons/42577