update 202
This commit is contained in:
parent
85b45fcbfe
commit
eff95054a8
@ -4,11 +4,14 @@
|
|||||||
|
|
||||||
|
|
||||||
class Solution:
|
class Solution:
|
||||||
def isHappy(self, n: int, status: list = []) -> bool:
|
def isHappy(self, n: int, status=None) -> bool:
|
||||||
|
if status is None:
|
||||||
|
status = []
|
||||||
|
|
||||||
str_n = str(n)
|
str_n = str(n)
|
||||||
total = 0
|
total = 0
|
||||||
for number in str_n:
|
for number in str_n:
|
||||||
total += int(number) * int(number)
|
total += int(number) ** 2
|
||||||
if total == 1:
|
if total == 1:
|
||||||
return True
|
return True
|
||||||
if str(total) in status:
|
if str(total) in status:
|
||||||
@ -19,5 +22,5 @@ class Solution:
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
number = 19
|
number = 13
|
||||||
print(Solution().isHappy(19))
|
print(Solution().isHappy(number))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user