Remove duplicates from a sorted array
So the simplest solutions is to use the available stl function. However there is obviously less to learn there.

#include &lt;algorithm&gt;
#include &lt;vector&gt;

int removeDuplicates(std::vector&lt;int&gt;&amp; nums) {
    nums.erase(std::unique(nums.begin(), nums.end()), nums.end()); ;
    return nums.size();
}