329. 전화번호 목록

아현·2021년 11월 11일
0

Algorithm

목록 보기
353/400
post-custom-banner

프로그래머스



1. Python



def solution(phone_book):
    phone_book.sort()

    for i in range(len(phone_book) - 1):
        if phone_book[i] == phone_book[i + 1][:len(phone_book[i])]:
            return False
    return True
    


  



2. C++



#include <string>
#include <vector>
#include <algorithm>
using namespace std;

bool solution(vector<string> phone_book) {
    sort(phone_book.begin(), phone_book.end());
    for(int i = 0; i < phone_book.size() - 1; i++){
        if(phone_book[i] == phone_book[i + 1].substr(0, phone_book[i].size()))
            return false;
    }
    
    return true;
}



profile
For the sake of someone who studies computer science
post-custom-banner

0개의 댓글