首页 > 其他 > 详细

LeetCode Remove Element

时间:2014-06-25 17:47:36      阅读:349      评论:0      收藏:0      [点我收藏+]
class Solution {
public:
    int removeElement(int A[], int n, int elem) {
        if (A == NULL || n < 1) return 0;
        int rpos = 0, wpos = 0;
        int removed = 0;
        while (rpos < n) {
            if (A[rpos] == elem) {
                rpos++;
                removed++;
            } else {
                A[wpos++] = A[rpos++];
            }
        }
        return n - removed;
    }
};

再水

LeetCode Remove Element,布布扣,bubuko.com

LeetCode Remove Element

原文:http://www.cnblogs.com/lailailai/p/3806063.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!