Simple Java Solution


  • 0
    A
    public class Solution {
        public int removeDuplicates(int[] nums) {
            if (nums == null || nums.length == 0){
                return 0;
            }
            int idx = 0;
            for (int i = 0; i < nums.length; i++){
                int ref = nums[i];
                int j = i+1;
                while (j < nums.length && nums[j] == ref){
                    j++;
                }
                nums[idx++] = ref;
                i = j - 1;
            }
            return idx;
        }
    }

Log in to reply
 

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