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 b02aceb commit 0d4dc45Copy full SHA for 0d4dc45
202-Happy-Number.py
@@ -0,0 +1,17 @@
1
+class Solution:
2
+ def isHappy(self, n: int) -> bool:
3
+ slow, fast = n, self.sumSquareDigits(n)
4
+
5
+ while slow != fast:
6
+ fast = self.sumSquareDigits(fast)
7
8
+ slow = self.sumSquareDigits(slow)
9
10
+ return True if fast == 1 else False
11
12
+ def sumSquareDigits(self, n):
13
+ output = 0
14
+ while n:
15
+ output += (n % 10) ** 2
16
+ n = n // 10
17
+ return output
0 commit comments