Happy Number

Easy

A number is happy when repeatedly replacing it with the sum of the squares of its digits eventually reaches 1.

A number that loops forever is not happy.

Example 1

isHappy()
Input
n = 19
Output
true

Why

1² + 9² = 82 → 68 → 100 → 1

Example 2

isHappy()
Input
n = 2
Output
false
Constraints
1 <= n <= 2^31 - 1

Topics

MathHash Table

Implement isHappy in the editor and return the answer — printing it is never graded.