Happy Number
Repeatedly replace positive integer n by the sum of squares of its decimal digits. Return whether this process reaches one.
Example 1
n = 19trueExplanation
19->82->68->100->1 reaches one.
Example 2
n = 2falseExplanation
2->4->16->37->58->89->145->42->20->4 cycles without reaching one.
Example 3
n = 1trueExplanation
The input already equals one.
Constraints
- 1 <= n <= 2147483647
Function contract
isHappyArguments: jsonSolutionRuns on your device
Loading draft…
Run: 3 examples; Submit: 32 cases, on your device.
19