码迷,mamicode.com
首页 > 其他好文 > 详细

Remove Duplicates from Sorted Array

时间:2015-04-10 14:53:03      阅读:103      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!