容器中元素的去重——ans.erase(unique(ans.begin(),ans.end()),ans.end());

啊,原来unique()函数,只是处理的连续的元素,比如 -1 -1 -1 1 2 -1 2 就处理成了 -1 1 2 -1 2 -1 -1并且返回5,之后eraser(5,7)剩下了 -1 1 2 -1 2 .

但这不是本意,为了去除重复元素,应该先 sort(),变成 -1 -1 -1 -1 1 2 2 再 unique(),再 eraser().

Remove consecutive duplicates in range

Removes all but the first element from every consecutive group of equivalent elements in the range [first,last).

又自己挖坑,自己跳了。

原文地址:https://www.cnblogs.com/qingcheng/p/3803125.html