Saturday, July 16, 2016

Reverse Array or String

Basic algorithm:
public void reverse(int[] nums, int left, int right){
    while(left        int temp = nums[left];
        nums[left]=nums[right];
        nums[right]=temp;
        left++;
        right--;
    }

}

No comments: