Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Next »

Remove Duplicates from Sorted Array

https://leetcode.com/problems/remove-duplicates-from-sorted-array/

func removeDuplicates(nums []int) int {
    i := 0
    j := 1
    
    for ; j < len(nums); j++ {
        if nums[j] == nums[j-1] {
            // duplicate
            continue
        }
        
        nums[i+1] = nums[j]
        i++
    }
    
    return i+1
}
  • No labels