80. Remove Duplicates from Sorted Array II

Posted 鸵鸟

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了80. Remove Duplicates from Sorted Array II相关的知识,希望对你有一定的参考价值。

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的主要内容,如果未能解决你的问题,请参考以下文章

80 remove duplicates from sorted array 2

80. Remove Duplicates from Sorted Array II

80. Remove Duplicates from Sorted Array II

80. Remove Duplicates from Sorted Array II

80. Remove Duplicates from Sorted Array II(js)

80. Remove Duplicates from Sorted Array II