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

神小逻辑 Remove Duplicates from Sorted Array

时间:2014-10-07 06:55:53      阅读:120      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   io   ar   sp   div   c   on   

/*
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

标签:style   blog   color   io   ar   sp   div   c   on   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!