Merge pull request #300 from betNevS/master

添加 0202.快乐数 go版
This commit is contained in:
Carl Sun
2021-06-01 10:42:12 +08:00
committed by GitHub

View File

@ -111,6 +111,24 @@ Python
Go 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: javaScript: