首页 > 其他 > 详细

神小逻辑 Remove Duplicates from Sorted Array

时间:2014-10-07 04:57:53      阅读:285      评论:0      收藏:0      [点我收藏+]
/*
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;
    }
}

 

神小逻辑 Remove Duplicates from Sorted Array

原文:http://www.cnblogs.com/leetcode/p/4008959.html

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