Skip to content

Commit

Permalink
add sol
Browse files Browse the repository at this point in the history
  • Loading branch information
ductnn committed Mar 25, 2024
1 parent 2624b23 commit 79ea04f
Showing 1 changed file with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// https://leetcode.com/problems/find-all-duplicates-in-an-array/description/

package main

import "fmt"

func findDuplicates(nums []int) []int {
cnt := make(map[int]int)
res := []int{}

for _, num := range nums {
cnt[num]++
// fmt.Println(cnt)
}

for num, count := range cnt {
if count > 1 {
res = append(res, num)
}
}

return res
}

func main() {
nums := []int{4, 3, 2, 7, 8, 2, 3, 1}
fmt.Println(findDuplicates(nums))
}

0 comments on commit 79ea04f

Please sign in to comment.