Title address:
https://www.lintcode.com/problem/reverse-array/description
Flip the array. code show as below:
public class Solution {
/**
* @param nums: a integer array
* @return: nothing
*/
public void reverseArray(int[] nums) {
// write your code here
int i = 0, j = nums.length - 1;
while (i < j) {
swap(nums, i++, j--);
}
}
private void swap(int[] nums, int i, int j) {
int tmp = nums[i];
nums[i] = nums[j];
nums[j] = tmp;
}
}
time complexity , space 。