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

'CS > 알고리즘' 카테고리의 다른 글

[Leetcode] 15. 3Sum  (0) 2023.05.01
[Leetcode] 1. Two Sum  (0) 2023.05.01
[Leetcode] 12. Integer to Roman  (0) 2023.05.01
[Leetcode] 55. Jump Game  (0) 2023.04.27
[Leetcode] 11. Container With Most Water  (0) 2023.04.27