解题思路:双指针
class Solution {
public int removeDuplicates(int[] nums) {
if(nums == null || nums.length == 0)
return 0;
int n = nums.length;
int p = 0;
int q = 1;
while(q < n)
{
if(nums[p] == nums[q])
{
p++;
}
else
{
nums[p+1] = nums[q];
p++;
q++;
}
}
return p+1;
}
}
易错:
1.没有判断数组为空
2。return的值