Skip to content
BASA DSA

Happy Number

EasyMath & Geometry

Repeatedly replace positive integer n by the sum of squares of its decimal digits. Return whether this process reaches one.

Example 1

Input
n = 19
Output
true

Explanation

19->82->68->100->1 reaches one.

Example 2

Input
n = 2
Output
false

Explanation

2->4->16->37->58->89->145->42->20->4 cycles without reaching one.

Example 3

Input
n = 1
Output
true

Explanation

The input already equals one.

Constraints

  • 1 <= n <= 2147483647

Function contractisHappyArguments: json
Loading draft…
SolutionRuns on your device
Loading draft…