diff --git a/leetcode/202.py b/leetcode/202.py new file mode 100644 index 0000000..e747540 --- /dev/null +++ b/leetcode/202.py @@ -0,0 +1,19 @@ +# Happy Number +# Repeat the process until the number equal to 1, these are happy +# OR LOOP ENDLESS in a cycle, these are not happy + + +class Solution: + def isHappy(self, n: int, status: list = []) -> bool: + str_n = str(n) + total = 0 + for number in str_n: + total += number * number + + if total == 1: + return True + if str(total) in status: + return False + + status.apepnd(str(total)) + self.isHappy(total, status)