zoukankan      html  css  js  c++  java
  • STL: unique

    unique

    Removes duplicate elements that are adjacent to each other in a specified range.

    template<class ForwardIterator>
       ForwardIterator unique(
          ForwardIterator _First, 
          ForwardIterator _Last
       );
    template<class ForwardIterator, class Predicate>
       ForwardIterator unique(
          ForwardIterator _First, 
          ForwardIterator _Last,
          Predicate _Comp
       );

    注,List provides a more efficient member function unique, which may perform better.

    These algorithms cannot be used on an associative container.

    如果想要移除所有的(包括不相邻的)重复元素,必须先将序列排序,使所有重复元素相邻,然后使用unique.

    unique_copy

    Copies elements from a source range into a destination range except for the duplicate elements that are adjacent to each other.

     
    template<class InputIterator, class OutputIterator> 
       OutputIterator unique_copy( 
          InputIterator _First,  
          InputIterator _Last,  
          OutputIterator _Result 
       ); 
    template<class InputIterator, class OutputIterator, class BinaryPredicate> 
       OutputIterator unique_copy( 
          InputIterator _First,  
          InputIterator _Last,  
          OutputIterator _Result, 
          BinaryPredicate _Comp, 
       );
  • 相关阅读:
    1351. 统计有序矩阵中的负数
    剑指 Offer 56
    39. 组合总和
    1619. 删除某些元素后的数组均值
    1380. 矩阵中的幸运数
    216. 组合总和 III
    面试题 08.03. 魔术索引
    1518. 换酒问题
    Xcode多进程调试:WKWebView
    Xcode编译WebKit
  • 原文地址:https://www.cnblogs.com/freewater/p/2953678.html
Copyright © 2011-2022 走看看