Skip to content

Commit d18ba5a

Browse files
committed
Create README - LeetHub
1 parent e11a17b commit d18ba5a

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

0202-happy-number/README.md

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<h2><a href="https://leetcode.com/problems/happy-number">202. Happy Number</a></h2><h3>Easy</h3><hr><p>Write an algorithm to determine if a number <code>n</code> is happy.</p>
2+
3+
<p>A <strong>happy number</strong> is a number defined by the following process:</p>
4+
5+
<ul>
6+
<li>Starting with any positive integer, replace the number by the sum of the squares of its digits.</li>
7+
<li>Repeat the process until the number equals 1 (where it will stay), or it <strong>loops endlessly in a cycle</strong> which does not include 1.</li>
8+
<li>Those numbers for which this process <strong>ends in 1</strong> are happy.</li>
9+
</ul>
10+
11+
<p>Return <code>true</code> <em>if</em> <code>n</code> <em>is a happy number, and</em> <code>false</code> <em>if not</em>.</p>
12+
13+
<p>&nbsp;</p>
14+
<p><strong class="example">Example 1:</strong></p>
15+
16+
<pre>
17+
<strong>Input:</strong> n = 19
18+
<strong>Output:</strong> true
19+
<strong>Explanation:</strong>
20+
1<sup>2</sup> + 9<sup>2</sup> = 82
21+
8<sup>2</sup> + 2<sup>2</sup> = 68
22+
6<sup>2</sup> + 8<sup>2</sup> = 100
23+
1<sup>2</sup> + 0<sup>2</sup> + 0<sup>2</sup> = 1
24+
</pre>
25+
26+
<p><strong class="example">Example 2:</strong></p>
27+
28+
<pre>
29+
<strong>Input:</strong> n = 2
30+
<strong>Output:</strong> false
31+
</pre>
32+
33+
<p>&nbsp;</p>
34+
<p><strong>Constraints:</strong></p>
35+
36+
<ul>
37+
<li><code>1 &lt;= n &lt;= 2<sup>31</sup> - 1</code></li>
38+
</ul>

0 commit comments

Comments
 (0)