#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].size() > phone_book[i+1].size())
        {
            if(phone_book[i].substr(0, phone_book[i+1].size()) == phone_book[i+1])
            {
                return false;
            }
        }
        else if(phone_book[i].size() == phone_book[i+1].size())
        {
            continue;
        }
        else
        {
            if(phone_book[i+1].substr(0, phone_book[i].size()) == phone_book[i])
            {
                return false;
            }
        }
    }
    
    return true;
}
cs

+ Recent posts