LeetCode Day64 Remove duplicates from sorted array II

Source
class Solution {
public:
    int removeDuplicates(vector<int>& nums) {
        if(nums.size()<=2) return nums.size();
        int n=1,tmp=nums[0],count=0;
        for(int i=1;i<nums.size();i++){
            if(nums[i]==tmp&&count==1){
                continue;
            }
            else{
                if(nums[i]==tmp) count++;
                else{
                    count=0;
                    tmp=nums[i];
                    }
                nums[n++]=tmp;
            }
        }
        return n;
    }
};