Remove Element

public class Solution {
    public int removeElement(int[] A, int elem) {
        if(A==null||A.length<1) return 0;
        // same http://www.cnblogs.com/springfor/p/3871046.html
         int len = 0;
         for(int i=0; i< A.length; i++){
             if(A[i]!=elem){
                 if(A[len]!=A[i]){
                     A[len] = A[i];
                 }
                 len++;
             }
         }
         return len;
    }
}

 

posted @ 2015-04-10 13:18  世界到处都是小星星  阅读(114)  评论(0编辑  收藏  举报