프로그래머스
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;
}