神小逻辑 Remove Duplicates from Sorted Array

/*
put all vaild new array from the 0 to new length

*/


public class Solution {
    public int removeDuplicates(int[] A) {
        if(A.length < 2)
            return A.length;
 
        int j = 0;
        int i = 1;
 
        while(i < A.length){
            if(A[i] == A[j]){
                i++;
            }else{
                A[++j] = A[i++];
            }    
        }
 
        return j+1;
    }
}

 

posted on 2014-10-07 04:19  brave_bo  阅读(105)  评论(0编辑  收藏  举报

导航