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
▲ Console

Install Talent Arabia

Get instant access to jobs and career tools on your device.