Skip to content

Commit

Permalink
remove duplicates and return unique nos in array
Browse files Browse the repository at this point in the history
  • Loading branch information
Nishi Davidson authored and Nishi Davidson committed Mar 27, 2020
1 parent 00261db commit a9a91cc
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions rm-duplicates.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package main

import (
"fmt"
)

func main() {

nums := []int{0,0,1,1,1,2,3,4,4}
fmt.Println(removeDuplicates(nums))

}

func removeDuplicates(nums []int) int {
m := make(map[int]int)

for i:=0; i<len(nums); i++ {
_, ok := m[nums[i]]
if ok == false {
m[nums[i]] = 1
} else {
if i != len(nums)-1 {
nums = append(nums[:i], nums[i+1:]...)
i = i-1
} else {
nums = nums[:i]
break
}
}
}

fmt.Println(m)
fmt.Println(nums)

return len(nums)
}

0 comments on commit a9a91cc

Please sign in to comment.