Skip to content

Commit

Permalink
update 349.md ๐Ÿ˜Ž
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaobinqt committed Sep 14, 2023
1 parent 21e0ab9 commit 2a2ac49
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions book.leetcode/docs/easy/349.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,19 @@ func intersection(nums1 []int, nums2 []int) []int {
}

var (
m1, m2 = make(map[int]interface{}), make(map[int]interface{})
set = make(map[int]struct{}, 0)
ret = make([]int, 0)
)

// ้‡ๅค็š„ไผš็›ดๆŽฅ่ฆ†็›–
for _, each := range nums1 {
m1[each] = nil
set[each] = struct{}{}
}

for _, each := range nums2 {
m2[each] = nil
}

ret := make([]int, 0)
for key, _ := range m1 {
if _, ok := m2[key]; ok {
ret = append(ret, key)
if _, ok := set[each]; ok {
ret = append(ret, each)
delete(set, each)
}
}

Expand Down

0 comments on commit 2a2ac49

Please sign in to comment.