Pointer j increases only for unique element.

class Solution {

public:

int removeDuplicates(vector<int>& nums) {

```
set<int> si;
int j=0;
for (int i=0; i<nums.size(); i++) {
if (si.find(nums[i]) == si.end()) {
si.insert(nums[i]);
nums[j++] = nums[i];
}
}
return j;
}
```

};