• + 1 comment

    My Java soluton with o(n) time complexity and o(1) space complexity:

    public static List<Integer> reverseArray(List<Integer> a) {
            // use a pointer at the start and the end
            //flip while the left pointer is less than the right pointer
            int left = 0, right = a.size() - 1;
            while(left < right){
                int leftVal = a.get(left);
                int rightVal = a.get(right);
                a.set(left, rightVal);
                a.set(right, leftVal);
                left++;
                right--;
            }
            return a;
        }