class Solution {public:int removeDuplicates(vector& nums) {map hash;vector result;int i=0;while(i<nums.size()){if(hash.find(nums[i])!=hash.end()){if(hash[nums[i]]<2){hash[nums[i]]++;result.push_back(nums[i]);}}else{hash[nums[i]]=1;result.push_back(nums[i]);}i++;}nums=result;return nums.size();}};