링크 : 전화번호 목록
import java.util.HashSet;
class Solution {
public boolean solution(String[] phone_book) {
boolean answer = true;
HashSet<String> set = new HashSet<String>();
for(int i=0; i<phone_book.length;i++)
set.add(phone_book[i]);
for(int i=0; i<phone_book.length;i++)
for(int j=1;j<phone_book[i].length();j++)
if(set.contains(phone_book[i].substring(0, j)))
return false;
return true;
}
}
class Solution {
public boolean solution(String[] phoneBook) {
for(int i=0; i<phoneBook.length-1; i++) {
for(int j=i+1; j<phoneBook.length; j++) {
if(phoneBook[i].startsWith(phoneBook[j])) {return false;}
if(phoneBook[j].startsWith(phoneBook[i])) {return false;}
}
}
return true;
}
}