기본 콘텐츠로 건너뛰기

프로그래머스 - 전화번호 목록

#include <string>
#include <vector>
#include <algorithm>

using namespace std;

bool solution(vector<string> phone_book) {
    sort(phone_book.begin(), phone_book.end());

    vector<string>::iterator it;
    for (it = phone_book.begin(); it != phone_book.end(); ++it) {

        vector<string>::iterator it2 = it;
        for (++it2; it2 != phone_book.end(); ++it2) {
            if ((*it2).find((*it).c_str(), 0, (*it).size()) != string::npos) {
                return false;
            }
        }
    }

    return true;
}

댓글

이 블로그의 인기 게시물