Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save luojiyin1987/f5781fa84353726b50b663293c17dd97 to your computer and use it in GitHub Desktop.
Save luojiyin1987/f5781fa84353726b50b663293c17dd97 to your computer and use it in GitHub Desktop.
Single Number
//write by myself
func singleNumber(nums []int) int {
temp :=map[int]int{}
var single int
for _ , n := range nums {
if _, ok := temp[n] ; ok {
temp[n] = temp[n]+1
} else {
temp[n] =0
}
}
for k,v := range temp{
if v== 0 {
single = k
}
}
return single
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment