unique function in C++

The unique function is a function used to remove duplicate elements from a collection

  If it is in an array, after calling this function, the place where the next pointer to remove the duplicate elements is returned.

If it is in a vector, it will return the iterator of the next position of the repeated element. After calling the erase function, the real deletion

sort(v.begin(), v.end(), cmp);
v.erase(unique(v.begin(), v.end()), v.end());

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325228558&siteId=291194637