prgms.42577 - 전화번호 목록

class Solution {
    public boolean solution(String[] phone_book) {
        boolean answer = true;
        for (int i = 0; i < phone_book.length; i++) {
            for (int j = 0; j < phone_book.length; j++) {
                if (i == j) continue;
                if (phone_book[i].length() <= phone_book[j].length() &&
                        phone_book[i].equals(phone_book[j].substring(0, phone_book[i].length()))) {
                    return false;
                }
            }
        }
        return answer;
    }
}
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;
    }
}
class Solution {
    public boolean solution(String[] phoneBook) {
        Arrays.sort(phoneBook);
        boolean result = true;
        for (int i=0; i<phoneBook.length-1; i++) {
            if (phoneBook[i+1].contains(phoneBook[i])) {
                result = false;
                break;
            }
        }
        return result;
    }
}
class Solution {
    public boolean solution(String[] phone_book) {
        String text = String.format(" %s", String.join(" ", phone_book));
        return !Arrays.stream(phone_book)
            .anyMatch(s -> text.split(String.format(" %s", s)).length > 2);
    }
}