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

80. Remove Duplicates from Sorted Array II

时间:2017-09-27 10:21:53      阅读:122      评论:0      收藏:0      [点我收藏+]

标签:color   ted   turn   remove   bsp   logs   i+1   ==   nbsp   

public class Solution {
    public int removeDuplicates(int[] nums) {
        if(nums.length<3)
            return nums.length;
        int i=1;
        int j=2;
        while(j<nums.length)
        {
            if(nums[i-1]==nums[i]&&nums[i]==nums[j])
                j++;
            else
            {
                i++;
                nums[i]=nums[j];
                j++;
            }
        }
        return i+1;
    }
}

 

public int removeDuplicates(int[] nums) {
    int i = 0;
    for (int n : nums)
        if (i < 2 || n > nums[i-2])
            nums[i++] = n;
    return i;
}

 

80. Remove Duplicates from Sorted Array II

标签:color   ted   turn   remove   bsp   logs   i+1   ==   nbsp   

原文地址:http://www.cnblogs.com/asuran/p/7599837.html

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