Skip to content

Instantly share code, notes, and snippets.

@gumeniukcom
Created April 2, 2020 16:52
Show Gist options
  • Save gumeniukcom/d7c1e09cd94c2ff4ea36de4a5fbaf952 to your computer and use it in GitHub Desktop.
Save gumeniukcom/d7c1e09cd94c2ff4ea36de4a5fbaf952 to your computer and use it in GitHub Desktop.
leetcode.com 202. Happy Number
func isHappy(n int) bool {
if n <=0 {
return false
}
used := make(map[int]bool)
used[n] = true
for n!=1 {
fmt.Println(n)
k:= n
sum := 0
for k>0 {
w:=k%10
k = k/10
sum +=w*w
}
if _, ok := used[sum]; ok {
return false
}
used[sum] = true
n = sum
}
return true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment