- Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy path_1213.java
33 lines (31 loc) · 1.03 KB
/
_1213.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
packagecom.fishercoder.solutions.secondthousand;
importjava.util.ArrayList;
importjava.util.List;
publicclass_1213 {
publicstaticclassSolution1 {
/*
* credit: https://leetcode.com/problems/intersection-of-three-sorted-arrays/discuss/397603/Simple-Java-solution-beats-100
*/
publicList<Integer> arraysIntersection(int[] arr1, int[] arr2, int[] arr3) {
List<Integer> result = newArrayList();
inti = 0;
intj = 0;
intk = 0;
while (i < arr1.length && j < arr2.length && k < arr3.length) {
if (arr1[i] == arr2[j] && arr1[i] == arr3[k]) {
result.add(arr1[i]);
i++;
j++;
k++;
} elseif (arr1[i] < arr2[j]) {
i++;
} elseif (arr2[j] < arr3[k]) {
j++;
} else {
k++;
}
}
returnresult;
}
}
}