Created
March 10, 2021 16:50
-
-
Save minhphong306/56b42752ca925936093b7b251bad36f0 to your computer and use it in GitHub Desktop.
find_not_duplicate_number_sol4.go
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
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