Share my clean Java code with insert index


  • 0
    T
    class Solution {
        public int removeDuplicates(int[] nums) {
            int insertIndex = 0;
            for(int i: nums){
                if(i != nums[insertIndex]){
                    nums[++insertIndex] = i;
                }
            }
            return insertIndex+1;
        }
    }
    

Log in to reply
 

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