int removeElement(int* nums, int numsSize, int val){ int pre=0; int cur=0; while(cur<numsSize) { if(nums[cur]!=val) { nums[pre]=nums[cur]; cur++; pre++; } else { cur++; } } return pre; }
void reverse(int* arr,int begin,int end) { while(begin<=end) { int tmp=arr[begin]; arr[begin]=arr[end]; arr[end]=tmp; begin++; end--; } } void rotate(int* nums, int numsSize, int k){ k %= numsSize; reverse(nums,0,numsSize-k-1); reverse(nums,numsSize-k,numsSize-1); reverse(nums,0,numsSize-1); return nums; }