Created
June 27, 2022 20:37
-
-
Save 11fl/8f23bc9425953267c3809a67dfa65f59 to your computer and use it in GitHub Desktop.
Get the different nubmbers from two slices
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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