Fundamentals/Happy Number
← PrevNext →
A "Happy Number" is defined as a number that after finite number of "steps" - where we sum the square of each digit each time - the result is a 1. Given a number n, determine whether it is a happy number.
As a challenge, complete this question under constant space.
Parameters
n: The number to check.
Result
true or false, depending on whether this number is a happy number.
Examples
Example 1
Input: n = 19
Output: true
Explanation
Example 2
Inputn = 2
Output: false
Explanation
...
Constraints
1 <= n < 2^31