cheetcode

139. Happy NumberEasy

Detect whether repeated digit-square sums eventually reach 1.

Write an algorithm to determine if a number n is happy.

A happy number is defined by replacing the number with the sum of the squares of its digits repeatedly until the number equals 1, or it loops endlessly in a cycle that does not include 1.

Examples

Input: n = 19
Output: true
Input: n = 2
Output: false

Constraints

  • 1 <= n <= 2,147,483,647