mirror of
https://github.com/devenperez/leetcode.git
synced 2026-06-13 03:27:07 +00:00
Time: 36 ms (70.15%), Space: 13.8 MB (95.83%) - LeetHub
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
class Solution:
|
||||
def isHappy(self, n: int) -> bool:
|
||||
def sumSquareDigits(x: int) -> int:
|
||||
sum = 0
|
||||
while x > 0:
|
||||
sum += (x % 10) ** 2
|
||||
x = int(x / 10)
|
||||
return sum
|
||||
|
||||
used = set({n})
|
||||
n = sumSquareDigits(n)
|
||||
|
||||
while n != 1:
|
||||
if n in used:
|
||||
return False
|
||||
used.add(n)
|
||||
n = sumSquareDigits(n)
|
||||
|
||||
return True
|
||||
Reference in New Issue
Block a user