我是靠谱客的博主 跳跃白羊,这篇文章主要介绍Remove Duplicates from Sorted Array,现在分享给大家,希望可以做个参考。

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;
    }
}

 

转载于:https://www.cnblogs.com/jiajiaxingxing/p/4414283.html

最后

以上就是跳跃白羊最近收集整理的关于Remove Duplicates from Sorted Array的全部内容,更多相关Remove内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(119)

评论列表共有 0 条评论

立即
投稿
返回
顶部