Problem
leetcode链接problem
相当于模拟了一个框,扫描整个向量,在扫描过程中,出现三个一样的情况就把第三个丢到最后去。
Code
class Solution {
public:
int removeDuplicates(vector<int>& nums) {
int length = nums.size();
for(int i = 0;i < length - 2;i++)
{
int temp1 = nums[i];
int temp2 = nums[i+1];
int temp3 = nums[i+2];
if(temp1 == temp2 && temp3 == temp2)
{
for(int j = i + 2;j < length - 1;j++)
{
nums[j] = nums[j + 1];
}
//把temp3所在的位置放到最后面去
length--;
i--;
}
}
return length;
}
};