My Java solution


  • 1
    M

    Check this out.

    public class Solution {
        public int removeDuplicates(int[] nums) {
            int len = 0;
            if(nums == null)
                return 0;
            if(nums.length <= 1)
                return 1;
            int ptr = 0;
            boolean flag = true;
            int curr = nums[0];
            int last = 0;
            for(int i = 0; i < nums.length; i++)
            {
                if(nums[i] != curr)
                    flag = false;
                else
                    flag = true;
                if(!flag)
                {
                    nums[ptr] = curr;
                    curr = nums[i];
                    ptr++;
                }
                last = nums[i];
            }
            nums[ptr++] = last;
            return ptr;
        }
    }
    

Log in to reply
 

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