Skip to content

Instantly share code, notes, and snippets.

@11fl
Created June 27, 2022 20:37
Show Gist options
  • Save 11fl/8f23bc9425953267c3809a67dfa65f59 to your computer and use it in GitHub Desktop.
Save 11fl/8f23bc9425953267c3809a67dfa65f59 to your computer and use it in GitHub Desktop.
Get the different nubmbers from two slices
package main
import "fmt"
var m = make(map[int]int)
func addToMap(s []int) {
for _, v := range s {
m[v] += 1
}
}
func main() {
res := []int{}
a := []int{1, 2, 5, 7}
b := []int{1, 3, 6, 7, 10}
addToMap(a)
addToMap(b)
for k, v := range m {
if v == 1 {
res = append(res, k)
}
}
fmt.Println(res)
// fmt.Println(m)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment