202. Happy Number

Practice Happy Number for free on NudgeCode: Easy, Array & Hash Table pattern. Write it in Python or JavaScript, run the tests in your browser, and ask for a hint when you are stuck.

Start with a positive integer n and repeatedly replace it with the sum of the squares of its digits. n is happy if this process eventually reaches 1; otherwise it loops forever through a cycle that never contains 1. Return whether n is happy.

Example

n = 19  ->  true    (1+81=82, 64+4=68, 36+64=100, 1+0+0=1)
n = 2   ->  false

Constraints