Archieve/알고리즘
[Leetcode] 202. Happy Number
mydailylogs
2023. 4. 27. 16:10
class Solution:
def isHappy(self, n: int) -> bool:
hashmap = {}
while n > 1:
nums = [int(x) for x in str(n)]
n = 0
for num in nums:
n += (num ** 2)
if hashmap.get(n, False):
return False
hashmap[n] = 1
return True