Problem List

Remove Duplicates From Sorted Array

March 03, 2025Go array, two pointereasy

Problem

Performance

Complexity

Go Solution
func removeDuplicates(nums[]int) int {
  hashMap:= make(map[int]bool)
  count:= 0
  for _, num := range nums {
    if _, exists := hashMap[num]; !exists {
      hashMap[num] = true
      nums[count] = num
      count++
    }
  }
  return count
}
LeetCode Problem Link