Problem
Code
import java.util.*;
class Solution {
public boolean solution(String[] phone_book) {
boolean answer = true;
Arrays.sort(phone_book);
for (int i=1; i<phone_book.length; i++) {
if (phone_book[i].length() > phone_book[i-1].length() && phone_book[i].startsWith(phone_book[i-1])) {
return false;
}
}
return answer;
}
}
Note
- startsWith(): 대상 문자열이 특정 문자 또는 문자열로 시작하는지 체크하는 함수(공백 포함) -> true/false 리턴
ex) String tmp = "자바";
tmp.startsWith("자") -> true 리턴
- endsWith(): 대상 문자열이 특정 문자 또는 문자열로 끝나는지 체크하는 함수 -> true/false 리턴