Skip to content

Commit 3e3d846

Browse files
committed
Update happy-number.js
1 parent b8eebcd commit 3e3d846

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

‎leetcode/happy-number.js‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,16 @@
1+
/**
2+
* Write an algorithm to determine if a number is "happy".
13
4+
* A happy number is a number defined by the following process:
5+
* Starting with any positive integer, replace the number by the sum of the squares of its digits,
6+
* and repeat the process until the number equals 1 (where it will stay),
7+
* or it loops endlessly in a cycle which does not include 1.
8+
* Those numbers for which this process ends in 1 are happy numbers.
9+
10+
* Example: 19 is a happy number
11+
12+
* 12 + 92 = 82
13+
* 82 + 22 = 68
14+
* 62 + 82 = 100
15+
* 12 + 02 + 02 = 1
16+
*/

0 commit comments

Comments
 (0)