강의로 돌아가기

제 코드 문제로 봐서는 맞는것 같은데 어디서 잘못됬는지 모르겠어요.

``````import java.util.HashMap;
import java.util.function.Predicate;

public class Solution {
public String solution(String[] participant, String[] completion) {
if (participant.length == completion.length + 1&&participant.length>=1&&participant.length<=100000) {
HashMap<String, String> map = new HashMap<>();
HashMap<String, String> map2 = new HashMap<>();
String[] pre = new String[participant.length];
String[] pre2 = new String[completion.length];
for (int i = 0; i < pre.length; i++)
pre[i] = participant[i];
for (int i = 0; i < pre2.length; i++)
pre2[i] = completion[i];
for (int i = 0; i < participant.length; i++)
map.put(participant[i], participant[i]);
for (int i = 0; i < completion.length; i++) {
map2.put(completion[i], completion[i]);
for (int j = i; j < map.size(); j++) {
if (map2.containsKey(participant[j]) || !pre[i].equals(pre[j]) || !pre2[i].equals(pre2[j])) {
break;
} else {
}
}
}
} else {
return null;
}

}

public static void main(String[] args) {
Solution s = new Solution();
String[] participant1 = { "leo", "kiki", "eden" };
String[] completion1 = { "eden", "kiki" };
String name = "";
name = s.solution(participant1, completion1);
System.out.println(name);
String[] participant2 = { "marina", "josipa", "nikola", "vinko", "filipa" };
String[] completion2 = { "josipa", "filipa", "marina", "nikola" };
name = s.solution(participant2, completion2);
System.out.println(name);
String[] participant3 = { "mislav", "stanko", "mislav", "ana" };
String[] completion3 = { "stanko", "ana", "mislav" };
name = s.solution(participant3, completion3);
System.out.println(name);
}

}
``````
작성중인 코드―Solution.java
``````1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import java.util.HashMap;
import java.util.function.Predicate;

public class Solution {
public String solution(String[] participant, String[] completion) {
if (participant.length == completion.length + 1&&participant.length>=1&&participant.length<=100000) {
HashMap<String, String> map = new HashMap<>();
HashMap<String, String> map2 = new HashMap<>();
String[] pre = new String[participant.length];
String[] pre2 = new String[completion.length];
for (int i = 0; i < pre.length; i++)
pre[i] = participant[i];
for (int i = 0; i < pre2.length; i++)
pre2[i] = completion[i];
for (int i = 0; i < participant.length; i++)
map.put(participant[i], participant[i]);
for (int i = 0; i < completion.length; i++) {
map2.put(completion[i], completion[i]);
for (int j = i; j < map.size(); j++) {
if (map2.containsKey(participant[j]) || !pre[i].equals(pre[j]) || !pre2[i].equals(pre2[j])) {
break;
} else {
}
}
}
} else {
return null;
}

}

public static void main(String[] args) {
Solution s = new Solution();
String[] participant1 = { "leo", "kiki", "eden" };
String[] completion1 = { "eden", "kiki" };
String name = "";
name = s.solution(participant1, completion1);
System.out.println(name);
String[] participant2 = { "marina", "josipa", "nikola", "vinko", "filipa" };
String[] completion2 = { "josipa", "filipa", "marina", "nikola" };
name = s.solution(participant2, completion2);
System.out.println(name);
String[] participant3 = { "mislav", "stanko", "mislav", "ana" };
String[] completion3 = { "stanko", "ana", "mislav" };
name = s.solution(participant3, completion3);
System.out.println(name);
}

}
``````