Simple java one pass beats 100% with two pointers


  • 0
    R
     public int removeDuplicates(int[] nums) {
            int currentpointer=0;
            int forwardpointer=0;
            while(forwardpointer<nums.length){
                if(nums[currentpointer]==nums[forwardpointer]){
                forwardpointer++;
                }
                else{
                    currentpointer++;
                    nums[currentpointer]=nums[forwardpointer];
                }
            }
            return currentpointer+1;
        }
    

Log in to reply
 

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