We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 39f7779 commit 8639e7fCopy full SHA for 8639e7f
202happy-number/main.go
@@ -0,0 +1,33 @@
1
+package main
2
+
3
+import "fmt"
4
5
+func isHappy(n int) bool {
6
+ n = digitResult(n)
7
+ m :=make(map[int]struct{},0)
8
+ for n!=1{
9
+ if _,ok:=m[n];!ok{
10
+ m[n]= struct{}{}
11
12
+ n =digitResult(n)
13
+ fmt.Println(n)
14
+ }else {
15
+ return false
16
+ }
17
18
+ return true
19
+}
20
+func digitResult(n int) int {
21
+ var res int
22
+ for n>0{
23
+ r :=n%10
24
+ res +=r*r
25
+ n =n/10
26
27
+ return res
28
29
30
+func main() {
31
+ fmt.Println(isHappy(2))
32
+ fmt.Println(isHappy(19))
33
59.02dui-lie-de-zui-da-zhi-lcof/main.go
@@ -0,0 +1,5 @@
+ $END$
0 commit comments