Java Solution


  • 0
    T
    public class Solution {
        public int removeDuplicates(int[] nums) {
            if(nums == null || nums.length == 0){
                return 0;
            }
            int length = nums.length;
            int temp = nums[0];
            for(int i = 1;i< length;){
                if(nums[i] == temp){
                    for(int j = i;j < length - 1 ; j++){
                        nums[j] = nums[j+1];
                    }
                    length-= 1;
                }else{
                    temp = nums[i];
                    i++;
                }
            }
            return length;
        }
    }
    

Log in to reply
 

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