My java solution


  • 0
    K
    public class Solution {
        public int removeDuplicates(int[] nums) {
            int i=0,j=1;
            while(j<nums.length){
                if(nums[j]==nums[i]) j++;
                else nums[++i]=nums[j++];
            }
            return i+1;
        }
    }

Log in to reply
 

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