MCPcopy Create free account
hub / github.com/neetcode-gh/leetcode / isHappy

Method isHappy

python/0202-happy-number.py:2–10  ·  view source on GitHub ↗
(self, n: int)

Source from the content-addressed store, hash-verified

1class Solution:
2 def isHappy(self, n: int) -> bool:
3 slow, fast = n, self.sumSquareDigits(n)
4
5 while slow != fast:
6 fast = self.sumSquareDigits(fast)
7 fast = self.sumSquareDigits(fast)
8 slow = self.sumSquareDigits(slow)
9
10 return True if fast == 1 else False
11
12 def sumSquareDigits(self, n):
13 output = 0

Callers

nothing calls this directly

Calls 1

sumSquareDigitsMethod · 0.95

Tested by

no test coverage detected