Share My Two pointer solution as a newbie


  • 0
    J

    public class Solution {
    public int removeDuplicates(int[] nums) { // pointers here j represents the newly generated array
    int j=1;
    for (int i= 0; i<nums.length; i++) {
    if (nums[i] == nums[j-1]) {
    continue;
    } else {
    j++;
    nums[j-1] = nums[i];
    }
    }
    return j;
    }
    }


Log in to reply
 

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