Happy Number

Given an integer n, determine whether it is a happy number. Repeatedly replace the number with the sum of the squares of its digits; if the process ends at 1, the number is happy.

Input Format

n = positive integer

Output Format

true if n is happy, otherwise false

Constraints

  • 1 <= n <= 2^31 - 1

Examples

Example 1:

Input:

n = 19

Output:

true

Explanation:

19 eventually reaches 1.

Example 2:

Input:

n = 2

Output:

false

Explanation:

2 falls into a cycle and never reaches 1.

Loading...
Happy Number - Math DSA Problem