Skip to content

Commit

Permalink
add sol
Browse files Browse the repository at this point in the history
  • Loading branch information
ductnn committed Mar 10, 2024
1 parent 36a06a8 commit 4ece390
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions leetcode/349.IntersectionofTwoArrays/IntersectionofTwoArrays.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// https://leetcode.com/problems/intersection-of-two-arrays

package main

import (
"fmt"
)

func intersection(nums1 []int, nums2 []int) []int {
res := []int{}

mx := [1001]bool{}
for _, x := range nums1 {
mx[x] = true
}

for _, x := range nums2 {
if mx[x] {
res = append(res, x)
mx[x] = false
}
}

return res
}

func main() {
nums1 := []int{1, 2, 2, 1}
nums2 := []int{2, 2}

fmt.Println(intersection(nums1, nums2))
}

0 comments on commit 4ece390

Please sign in to comment.