Written by
java-style
on
on
[level2] 프로그래머스 - 전화번호 목록(JAVA)
[level2] 프로그래머스 - 전화번호 목록(JAVA)
728x90
- 모든 전화번호를 Set에 넣어준다.
- 각 전화번호를 하나씩 잘라보면서 Set에 있는지 확인한다.
import java.util.*; class Solution { public boolean solution(String[] phone_book) { Set num = new HashSet<>(); num.addAll(Arrays.asList(phone_book)); for (String phone : phone_book) { for(int i = 1; i < phone.length(); i++) if(num.contains(phone.substring(0, i))) return false; } return true; } }
728x90
from http://jisunshine.tistory.com/164 by ccl(A) rewrite - 2021-09-14 21:01:28