[PRO] 자동완성

천호영·2022년 9월 17일
0

알고리즘

목록 보기
55/100
from collections import defaultdict

def solution(words):
    answer = 0
    
    cnt_defaultdict = defaultdict(int)
    
    # 1,000,000
    for word in words:
        for i in range(1,len(word)+1):
            cnt_defaultdict[word[:i]] += 1
    
    for word in words:
        for i in range(1,len(word)+1):
            if cnt_defaultdict[word[:i]] == 1:
                break
        answer += i
    
    return answer
profile
성장!

0개의 댓글