In contrast to findet the longest common subsequence in Strings I can't add arrays as simple as with Strings, which makes the problem harder for me.
The code marked with * just illustrates what I want to achieve.
Is this possible without the use of additional dependencies?
static long[] lgs(long[] x, long[] y) {
if ((x.length == 0 || y.length == 0)) {
return new long[] {};
}
else if (x[x.length-1] == y[y.length -1]) {
System.out.println(x[x.length-1]);
return *x[x.length -1] +* lgs(Arrays.copyOf(x, x.length -1), Arrays.copyOf(y, x.length-1));
}
else {
long[] s1 = lgs(Arrays.copyOf(x, x.length -1), y);
long[] s2 = lgs(x, Arrays.copyOf(y, y.length-1));
return (x.length > y.length) ? s1 : s2;
}
}