https://school.programmers.co.kr/learn/courses/30/lessons/42577
- 배열 정렬.
- 핵심 ✨Point : startsWith
앞 문자열이 뒤 문자열의 접두사인지 확인.if(phone_book[i+1].startsWith(phone_book[i])){ return false; }
import java.util.*;
class Solution {
public boolean solution(String[] phone_book) {
Arrays.sort(phone_book);
for(int i = 0; i < phone_book.length - 1; i++){
if(phone_book[i+1].startsWith(phone_book[i])){
return false;
}
}
return true;
}
}