Happy Number
Easy
Math
Math
Hash Table
Determine if a number is happy. Replace number by sum of squares of digits. Happy if reaches 1.
Constraints
1 ≤ n ≤ 2^31 - 1
Examples
Example 1:
Input: 19
Output: true
Explanation: 1²+9²=82→8²+2²=68→...→1
Example 2:
Input: 2
Output: false
Tests:
Runtime:
Memory:
Test
Input:
Expected:
Got:
Click Run Code to test against sample cases, or Submit to test against all cases.
▲ Console