Make reverse a lot simpler
This commit is contained in:
parent
b38f5ffc8e
commit
c68ec4e11b
Binary file not shown.
|
@ -20,18 +20,9 @@ public class RecursiveExercise {
|
||||||
return null;
|
return null;
|
||||||
if (ht.length == 1)
|
if (ht.length == 1)
|
||||||
return ht.clone();
|
return ht.clone();
|
||||||
return append(new int[] { ht[ht.length - 1] }, append(
|
return append(reverse(MyArrayUtil.tail(ht)),new int[] {MyArrayUtil.head(ht)});
|
||||||
reverse(MyArrayUtil.tail(removeLast(ht.clone(), new int[ht.length - 1], 0))), new int[] { ht[0] }));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove the last element
|
|
||||||
|
|
||||||
public static int[] removeLast(int[] ia1, int[] ia2, int i) {
|
|
||||||
ia2[i] = ia1[i];
|
|
||||||
if (i == ia2.length - 1)
|
|
||||||
return ia2;
|
|
||||||
return removeLast(ia1, ia2, i + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isIn(int x, int[] a) throws Exception {
|
public static boolean isIn(int x, int[] a) throws Exception {
|
||||||
// fill your code here
|
// fill your code here
|
||||||
|
|
Loading…
Reference in New Issue