알고리즘/[2021] 프로그래머스
[프로그래머스] 전화번호 목록 - C++
Sorrel
2021. 5. 31. 01:27
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
bool solution(vector<string> phone_book) {
bool answer = true;
//접두사인 경우가 있으면 false
//접두사인 경우가 없으면 true
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()))
answer = false;
}
return answer;
}