Skip to content

Commit 563e69d

Browse files
authored
Update 0202-Happy-Numbers.md
1 parent 5e7f485 commit 563e69d

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

dsa-solutions/lc-solutions/0200-0299/0202-Happy-Numbers.md

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,15 @@ Explanation:
3838
Input: `n = 2`
3939
Output: `false`
4040
Explanation:
41-
2^2 = 4
42-
4^2 = 16
43-
1^2 + 6^2 = 37
44-
3^2 + 7^2 = 58
45-
5^2 + 8^2 = 89
46-
8^2 + 9^2 = 145
47-
1^2 + 4^2 + 5^2 = 42
48-
4^2 + 2^2 = 20
49-
2^2 + 0^2 = 4 (cycle repeats endlessly)
41+
$2^2 = 4$
42+
$4^2 = 16$
43+
$1^2 + 6^2 = 37$
44+
$3^2 + 7^2 = 58$
45+
$5^2 + 8^2 = 89$
46+
$8^2 + 9^2 = 145$
47+
$1^2 + 4^2 + 5^2 = 42$
48+
$4^2 + 2^2 = 20$
49+
$2^2 + 0^2 = 4$ (cycle repeats endlessly)
5050

5151
## Constraints
5252

@@ -158,4 +158,3 @@ var isHappy = function(n) {
158158

159159
## Conclusion
160160
The provided solutions use a similar approach to solve the happy number problem across different programming languages. They efficiently detect cycles and determine if a number eventually leads to 1 or loops endlessly. The use of a set ensures that the algorithm runs in linear time relative to the number of digits in `n`, making it suitable for the given constraints.
161-

0 commit comments

Comments
 (0)