[9/12] 전화번호 목록 (x)

이경준·2021년 9월 12일
0

코테

목록 보기
103/140

레벨2 문제 실패

효율적인 코드

def solution(pb):
    answer = True
    pb.sort()
    
    for i in range(len(pb)-1):
        if ( len(pb[i]) < len(pb[i+1]) and pb[i] == pb[i+1][:len(pb[i])] ):
            answer = False
            break
    
    return answer

로직

  • str 자료형 상태로 정렬하면, 접두어가 포함된 단어는 해당 접두어 앞에 위치하게 된다.
profile
The Show Must Go On

0개의 댓글