조금 더 난이도가 있는데 정렬을 했을 때 바로 뒤랑만 비교하면 된다는 것을 떠올려야하기 때문이다. (promise)
바로 뒤가 다르면 그 이상은 같을 수가 없다.
#include <bits/stdc++.h>
using namespace std;
/*
사전순 정렬 후 find 결과가 begin인게 존재하면 true
*/
bool solution(vector<string> p) {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
sort(p.begin(), p.end());
int l = p.size();
for (int i = 0; i < l-1; i++) {
if (p[i+1].find(p[i]) == 0)
return false;
}
return true;
}
#include <bits/stdc++.h>
using namespace std;
/*
큰 문자를 잘라나가며 있는지 확인
*/
bool solution(vector<string> p) {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
unordered_map<string, bool> m;
for (int i = 0; i < p.size(); i++)
m[p[i]] = true;
for (string e : p){
for (int i = 0; i < e.length() - 1; i++){
if (m[e.substr(0, i+1)])
return false;
}
}
return true;
}