update 202
This commit is contained in:
parent
530f995d46
commit
a35d60437a
19
leetcode/202.py
Normal file
19
leetcode/202.py
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
# Happy Number
|
||||||
|
# Repeat the process until the number equal to 1, these are happy
|
||||||
|
# OR LOOP ENDLESS in a cycle, these are not happy
|
||||||
|
|
||||||
|
|
||||||
|
class Solution:
|
||||||
|
def isHappy(self, n: int, status: list = []) -> bool:
|
||||||
|
str_n = str(n)
|
||||||
|
total = 0
|
||||||
|
for number in str_n:
|
||||||
|
total += number * number
|
||||||
|
|
||||||
|
if total == 1:
|
||||||
|
return True
|
||||||
|
if str(total) in status:
|
||||||
|
return False
|
||||||
|
|
||||||
|
status.apepnd(str(total))
|
||||||
|
self.isHappy(total, status)
|
Loading…
x
Reference in New Issue
Block a user