Find duplicate number on a given integer array in Golang

IT doubts

/*** Here we can create a map where key will be provided items in array and value will be the occurrence  **/

package main
import (
“fmt”
)
func main() {
a := []int{1,2, 3, 5, 6,6,5,5}
myMap := make(map[int]int)

for _, val:= range a{

if _, ok := myMap[val]; ok {
myMap[val] = myMap[val] +1
continue
}
myMap[val] = 1
}
for key, val:= range myMap{
if val > 1{
fmt.Printf(“duplicate no is %v: with occurrence %v \n”,key, val)
}
}

}


Leave a Reply

Your email address will not be published. Required fields are marked *