Share my java solution


  • 0
    A
    public class Solution {
    public int removeDuplicates(int[] nums) {
        if(null==nums) return 0;
        int len = nums.length;
        if(len<=2) return len;
        int p=2;
        int i=2;
        while(i<=len-1){
            if(nums[p-2]==nums[p-1] && nums[i]==nums[p-1]){
                i++;
            }else{
                nums[p++] = nums[i++];
            }
        }
        return p;
    }
    

    }


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.