-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcoderByte_Find_Intersection.java
More file actions
59 lines (50 loc) · 1.41 KB
/
Copy pathcoderByte_Find_Intersection.java
File metadata and controls
59 lines (50 loc) · 1.41 KB
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
54
55
56
57
58
59
import java.util.*;
import java.io.*;
class Main {
public static String FindIntersection(String[] strArr) {
// code goes here
List<String> first = new ArrayList<>();
Set<String> second = new HashSet<>();
String res = "";
for(int i=0; i<strArr[0].length(); i++){
String str = "";
if(strArr[0].indexOf(',', i) < 0){
str = strArr[0].substring(i, strArr[0].length());
i = strArr[0].length();
}else{
str = strArr[0].substring(i, strArr[0].indexOf(',', i));
i = i + str.length() + 1;
}
first.add(str);
}
for(int i=0; i<strArr[1].length(); i++){
String str = "";
if(strArr[1].indexOf(',', i) < 0){
str = strArr[1].substring(i, strArr[1].length());
i = strArr[1].length();
}else{
str = strArr[1].substring(i, strArr[1].indexOf(',', i));
i = i + str.length() + 1;
}
second.add(str);
}
int index=0;
for(String str: first){
if(second.contains(str)){
if(index ==0){
res = res.concat(str);
index++;
}else{
res = res.concat(",".concat(str));
}
}
}
if(res.equals("")) return "false";
return res;
}
public static void main (String[] args) {
// keep this function call here
Scanner s = new Scanner(System.in);
System.out.print(FindIntersection(s.nextLine()));
}
}