Check if a Number is a Magic Number

Given a positive integer n, repeatedly replace it with the sum of its decimal digits until one digit remains. Return true if that final digit is 1; otherwise…

Given a positive integer `n`, repeatedly replace it with the sum of its decimal digits until one digit remains. Return `true` if that final digit is 1; otherwise return `false`.

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

Example 1: input n = 1729; output true. 1 + 7 + 2 + 9 = 19, then 1 + 9 = 10, then 1 + 0 = 1.

Example 2: input n = 99; output false. 9 + 9 = 18, then 1 + 8 = 9.

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