diff --git a/src/ArrayManipulation.java b/src/ArrayManipulation.java index 5d72748..68c95cc 100644 --- a/src/ArrayManipulation.java +++ b/src/ArrayManipulation.java @@ -1,31 +1,62 @@ import java.util.Arrays; - public class ArrayManipulation { - - + public static int[] reverseArray(int[] arr) { - - for (int i = 0; i < arr.length/2; i++) { - int tmp = arr[i]; - arr[i] = arr[arr.length - 1 - i]; - arr[arr.length - 1 - i] = tmp; + for (int i = 0; i < arr.length/2; i++) { + int tmp = arr[i]; + arr[i] = arr[arr.length - 1 - i]; + arr[arr.length - 1 - i] = tmp; } return arr; - } + } public static int[] removeFirst(int[] arr) { - + if (arr == null || arr.length==0) { + int[] result = new int[0]; + return result; + } + if(arr.length == 1||arr.length == 0) { + return arr; + } + int[] result = new int[arr.length-1]; + for(int a=1;a