Skip to content

Commit

Permalink
프로그래머스 전화번호 목록 java solution
Browse files Browse the repository at this point in the history
  • Loading branch information
mong3125 committed May 2, 2024
1 parent b75b28a commit 2cc73b2
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions mong3125/해시.P_전화번호목록.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import java.util.HashSet;

class Solution {
public boolean solution(String[] phone_book) {

HashSet<String> set = new HashSet<>();

for (String phoneNum : phone_book) {
set.add(phoneNum);
}

for (String phoneNum : phone_book) {
for (int i = 0; i < phoneNum.length(); i++) {
if (set.contains(phoneNum.substring(0, i))) return false;
}
}

return true;
}
}

0 comments on commit 2cc73b2

Please sign in to comment.