Check if a Number is Happy

Given a positive integer n, repeatedly replace it with the sum of the squares of its decimal digits. Return true if this process reaches 1. Return false if it…

Given a positive integer `n`, repeatedly replace it with the sum of the squares of its decimal digits. Return `true` if this process reaches 1. Return `false` if it enters a cycle that never reaches 1.

- `1 ≤ n ≤ 10^6` - `n` is always a positive integer.

Example 1: input n = 19; output true. The sequence is 19 → 82 → 68 → 100 → 1.

Example 2: input n = 2; output false. The sequence eventually repeats instead of reaching 1.

Category: Math. Topic: math. Difficulty: Easy. Patterns: math.