首页 > 其他 > 详细

linux驱动的类class及其节点

时间:2014-03-12 00:43:01      阅读:536      评论:0      收藏:0      [点我收藏+]

题目:

Given an array and a value, remove all instances of that value in place and return the new length.

The order of elements can be changed. It doesn‘t matter what you leave beyond the new length.


解题思路:设置两个指针pa,pb,pa指针从0开始依次向n-1滑动,当pa指向的元素不是待删除的元素时,将pa指向的元素赋给pb指向的元素,同时pb向前滑动。


代码:

class Solution {
public:
    int removeElement(int A[], int n, int elem) {
        int pa,pb=0;
        for(pa=0;pa<n;pa++){
            if(A[pa]!=elem){
                A[pb++]=A[pa];
            }
        }
        return pb;
    }
};


linux驱动的类class及其节点,布布扣,bubuko.com

linux驱动的类class及其节点

原文:http://blog.csdn.net/hustyangju/article/details/21018103

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