-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path202.py
More file actions
28 lines (27 loc) · 678 Bytes
/
202.py
File metadata and controls
28 lines (27 loc) · 678 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
class Solution:
def isHappy(self, n):
def convert_array(n):
res=[]
while n>=10:
res.append(n%10)
n=n//10
res.append(n)
res.reverse()
return res
def convert_num(num):
res=0
for i in num:
res+=pow(i,2)
return res
list_n=[n]
while True:
array_n=convert_array(n)
n=convert_num(array_n)
if n==1:
return True
if n in list_n:
return False
else:
list_n.append(n)
n=19
print(Solution().isHappy(n))