描述
原地翻转给出的数组 nums
原地意味着你不能使用额外空间
您在真实的面试中是否遇到过这个题? 是
样例
给出 nums
= [1,2,5]
返回 [5,2,1]
无难度题目
class Solution {
public:
/**
* @param nums: a integer array
* @return: nothing
*/
void reverseArray(vector<int> &nums) {
// write your code here
int left=0;
int right=nums.size()-1;
while(left<right){
int tmp=nums[left];
nums[left]=nums[right];
nums[right]=tmp;
left++;
right--;
}
}
};