1 // 注意:需要同时改变传入的数组的值
2 class Solution {
3 public:
4 int removeDuplicates(vector<int>& nums) {
5 map<int, int>m;
6 int count = 0;
7 vector<int> ans;
8 for (int i = 0; i < nums.size(); i++){
9 if (m[nums[i]] == 0)
10 {
11 ans.push_back(nums[i]);
12 m[nums[i]]++;
13 count++;
14 }
15 }
16 ans.resize(count);
17 nums = ans;
18 return count;
19 }
20 };