Skip to content

Instantly share code, notes, and snippets.

@minhphong306
Created March 10, 2021 16:50
Show Gist options
  • Save minhphong306/56b42752ca925936093b7b251bad36f0 to your computer and use it in GitHub Desktop.
Save minhphong306/56b42752ca925936093b7b251bad36f0 to your computer and use it in GitHub Desktop.
find_not_duplicate_number_sol4.go
func solution4(arr []int) int {
var sumSingle, sumAll int
mapCheck := make(map[int]bool)
for _, item := range arr {
if _, ok := mapCheck[item]; !ok {
sumSingle += item
mapCheck[item] = true
}
sumAll += item
}
return sumSingle*2 - sumAll
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment