80

Description:

 

 

Code:

public int removeDuplicates(int[] nums) {
    int count = 1, repeat = 1;

    for (int i = 1; i < nums.length; i++) {
        if (nums[i] == nums[i - 1]) {
            repeat ++;
            if (repeat <= 2){
                count ++;
                nums[count-1] = nums[i];
            }
        }else{
            count ++;
            repeat = 1;
            nums[count-1] = nums[i];
        }
    }
    return count;
}

  

 

posted @ 2019-04-14 20:35  Doris7  阅读(98)  评论(0编辑  收藏  举报