Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 0b882f5

Browse files
[211115] 전화번호 목록
1 parent 3b58822 commit 0b882f5

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import java.util.*;
2+
3+
class Solution {
4+
public boolean solution(String[] phone_book) {
5+
boolean answer = true;
6+
Map<String, String> map = new HashMap<>();
7+
8+
Arrays.sort(phone_book);
9+
for(String phone_number : phone_book){
10+
map.put(phone_number, "1");
11+
}
12+
13+
for(String phone_number : phone_book){
14+
for(int i=0; i<phone_number.length(); i++){
15+
String str = phone_number.substring(0, i);
16+
if(map.containsKey(str)){
17+
return false;
18+
}
19+
}
20+
}
21+
22+
// Hash없이 푼다면 startsWith
23+
// Arrays.sort(phone_book);
24+
// for (int i=0; i<phone_book.length-1; i++) {
25+
// if (phone_book[i+1].startsWith(phone_book[i])) {
26+
// answer = false;
27+
// break;
28+
// }
29+
// }
30+
31+
return answer;
32+
}
33+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /