My JAVA Solution


  • 0
    S
    public class Solution {
        public int removeDuplicates(int[] nums) {
            if (nums.length == 0)
                return 0;
        
            int sum = 1;
        
            for (int i=1; i<nums.length; i++) {
                if (nums[i-1] != nums[i])
                    nums[sum++] = nums[i];
            }
            return sum;
        }
    }

Log in to reply
 

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