Mixture

身未动,心已远

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

统计

STL: remove

leetcode:Remove Element

code from: https://github.com/soulmachine/leetcode

class Solution {
public:
    int removeElement(int A[], int n, int elem) {
        return distance(A,remove(A,A+n,elem));
    }
};

又是STL一句话搞定。distance之前已经学过了,正好复习一下:

distance(InputIterator first, InputIterator last), 返回的是两个迭代器的距离。

remove的说明是这样的:

template <class ForwardIterator, class T>
  ForwardIterator remove (ForwardIterator first, ForwardIterator last, const T& val);

 Transforms the range [first,last) into a range with all the elements that compare equal to val removed, and returns an iterator to the new end of that range.

 

posted on   parapax  阅读(190)  评论(0编辑  收藏  举报

点击右上角即可分享
微信分享提示