Concise JAVA solution


  • 0
    L
    public class Solution {
        public int removeDuplicates(int[] nums) {
            if(nums == null) return 0;
            int counter = 0;
            for(int i = 0; i < nums.length; i++) {
                if(counter < 2 || nums[i] != nums[counter-2]) nums[counter++] = nums[i];
            }
            return counter;
        }
    }
    

Log in to reply
 

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