添加 0202.快乐数 go版

This commit is contained in:
NevS
2021-05-31 22:26:44 +08:00
committed by GitHub
parent 5043002ed6
commit 659595f2b4

View File

@ -111,6 +111,24 @@ Python
Go
```go
func isHappy(n int) bool {
m := make(map[int]bool)
for n != 1 && !m[n] {
n, m[n] = getSum(n), true
}
return n == 1
}
func getSum(n int) int {
sum := 0
for n > 0 {
sum += (n % 10) * (n % 10)
n = n / 10
}
return sum
}
```
javaScript: