intremoveDuplicates(vector<int>& nums){ int res = nums.size(); if (res == 0) return0; int temp = nums[0]; auto it = nums.begin() + 1; while (it != nums.end()) { int d = *it; if (d == temp) { nums.erase(it); res--; continue; } temp = d; it++; } return res; }
intremoveDuplicates(vector<int>& nums){ int res = nums.size(); if (res == 0) return0; auto it1 = nums.begin(); auto it2 = nums.begin() + 1; while (it2 != nums.end()) { int d = *it1; int t = *it2; while (t == d) { it2++; res--; if (it2 != nums.end()) t = *it2; else return res; } it1++; it2++; *it1 = t; } return res; }