题目一
题目链接
void reverse(int* arr,int left,int right)
{
while(left<right)
{
int tmp=arr[left];
arr[left]=arr[right];
arr[right]=tmp;
left++;
right--;
}
return arr;
}
void rotate(int* nums, int numsSize, int k)
{
int num=k%numsSize;
if(num==0)
return nums;
reverse(nums,0,numsSize-num-1);
reverse(nums,numsSize-num,numsSize-1);
reverse(nums,0,numsSize-1);
return nums;
}
题目2:
题目链接
//双指针
int removeElement(int* nums, int numsSize, int val)
{
int slow=0;
int fast=0;
while(fast<numsSize)
{
if(nums[fast]!=val)
{
nums[slow]=nums[fast];
slow++;
fast++;
}
else
{
fast++;
}
}
return slow;
}