Download Happy Number.py
class Solution(object): def isHappy(self, n): """ :type n: int :rtype: bool """ # https://en.wikipedia.org/wiki/Happy_number seen_numbers = set() while n > 1 and n not in seen_numbers: seen_numbers.add(n) n = sum(map(lambda x: int(x) * int(x), list(str(n)))) return n == 1
Leetcode 202 Happy Number problem solution in python3 with explanation. This is the best place to expand your knowledge and get prepared for your next interview.
Feedback is the most important part of any website.
If you have any query, suggestion or feedback, Please feel free to contact us.