Skip to content

Instantly share code, notes, and snippets.

@luojiyin1987
Last active August 6, 2017 08:34
Show Gist options
  • Save luojiyin1987/a62b0f1bb098e02c3fcd0036b689845b to your computer and use it in GitHub Desktop.
Save luojiyin1987/a62b0f1bb098e02c3fcd0036b689845b to your computer and use it in GitHub Desktop.
Find the Difference
func findTheDifference(s string, t string) byte {
var ans int32
ans = 0
for _, cs := range s {
ans ^= cs
}
for _, ct := range t {
ans ^= ct
}
return byte(ans)
}
func findTheDifference(s string, t string) byte {
//var r byte
/*
countS := make(map[byte]int, 0)
for _, v := range []byte(s){
countS[v]++
}
countT := make(map[byte]int, 0)
for _, v := range []byte(t){
countT[v]++
}
for k,v := range countT {
_, ok := countS[k]
if !ok {
return k
}
if v != countS[k]{
return k
}
}
return r
*/
u := []byte(s + t)
d := 0
for _,v := range u {
d ^= int(v)
}
return byte(d)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment