forked from rpj911/LeetCode_algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FindSame.java
38 lines (30 loc) · 934 Bytes
/
FindSame.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
package Algorithms;
import java.util.LinkedList;
public class FindSame {
public static LinkedList<Integer> findSameNum(int[] A, int[] B) {
LinkedList<Integer> result = new LinkedList<Integer>();
int i = 0,j = 0;
while(true) {
if (A[i] == B[j]) {
result.add(A[i]);
i++;
j++;
} else if (A[i] < B[j]) {
i++;
} else {
j++;
}
if (i == A.length || j == B.length) {
break;
}
}
return result;
}
public static void main(String[] args) {
int[] A = {0,1,2,4,7,8,10};
int[] B = {2,3,4,5,6,10};
LinkedList<Integer> result = FindSame.findSameNum(A, B);
System.out.printf(result.toString());
System.out.printf("%d", (-5)%3);
}
}