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 9c763fa

Browse files
Merge pull request #10 from EunjiShin/master
[2주차]
2 parents 4b3caab + 0b882f5 commit 9c763fa

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import java.util.*;
2+
3+
class Solution {
4+
public String solution(String[] participant, String[] completion) {
5+
String answer = "";
6+
Map<String, Integer> map = new HashMap<>();
7+
8+
for(String str : participant){
9+
map.put(str, map.getOrDefault(str, 0)+1);
10+
}
11+
12+
for(String str : completion){
13+
map.put(str, map.get(str)-1);
14+
}
15+
16+
for(String key : map.keySet()){
17+
if(map.get(key) == 1){
18+
answer = key;
19+
}
20+
}
21+
22+
return answer;
23+
}
24+
}
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 によって変換されたページ (->オリジナル) /