首页 > 其他 > 详细

Remove Duplicates from Sorted Array

时间:2015-04-10 14:51:09      阅读:95      评论:0      收藏:0      [点我收藏+]
public class Solution {
    public int removeDuplicates(int[] A) {
        if(A==null || A.length==0) return 0;
        // 巧妙的做法http://www.cnblogs.com/springfor/p/3871038.html
        int len =0; // 记录最后一个不重复的点在新数组中位置,尾端
        for(int i=1; i<A.length;i++){
            if(A[i]!=A[i-1]){
                if(A[i]!=A[len]){
                    A[len+1] = A[i];
                    len++;
                }
            }
        }
        return len+1;
    }
}

 

Remove Duplicates from Sorted Array

原文:http://www.cnblogs.com/jiajiaxingxing/p/4414283.html

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