Simple Java Solution with one pointer

  • 0

    ***This is method just needs one int ,and needn't any other value
    ***The main core is the i is much fast increasing than num, so I save the value in nums [num-1].

    public class Solution {
    public int removeDuplicates(int[] nums) {
    int num=1,len=nums.length;
    return len;
    for(int i=1;i<nums.length;i++)
    if(nums[num-1]!=nums[i]) //if not the same,just save the different number in the original nums array
    return num;



Log in to reply

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