Skip to content

Commit 96a839a

Browse files
committed
Create README - LeetHub
1 parent 7a2930c commit 96a839a

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

191-number-of-1-bits/README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<h2><a href="https://leetcode.com/problems/number-of-1-bits/">191. Number of 1 Bits</a></h2><h3>Easy</h3><hr><div><p>Write a function that takes an unsigned integer and returns the number of '1' bits it has (also known as the <a href="http://en.wikipedia.org/wiki/Hamming_weight" target="_blank">Hamming weight</a>).</p>
2+
3+
<p><strong>Note:</strong></p>
4+
5+
<ul>
6+
<li>Note that in some languages, such as Java, there is no unsigned integer type. In this case, the input will be given as a signed integer type. It should not affect your implementation, as the integer's internal binary representation is the same, whether it is signed or unsigned.</li>
7+
<li>In Java, the compiler represents the signed integers using <a href="https://en.wikipedia.org/wiki/Two%27s_complement" target="_blank">2's complement notation</a>. Therefore, in <strong>Example 3</strong>, the input represents the signed integer. <code>-3</code>.</li>
8+
</ul>
9+
10+
<p>&nbsp;</p>
11+
<p><strong>Example 1:</strong></p>
12+
13+
<pre><strong>Input:</strong> n = 00000000000000000000000000001011
14+
<strong>Output:</strong> 3
15+
<strong>Explanation:</strong> The input binary string <strong>00000000000000000000000000001011</strong> has a total of three '1' bits.
16+
</pre>
17+
18+
<p><strong>Example 2:</strong></p>
19+
20+
<pre><strong>Input:</strong> n = 00000000000000000000000010000000
21+
<strong>Output:</strong> 1
22+
<strong>Explanation:</strong> The input binary string <strong>00000000000000000000000010000000</strong> has a total of one '1' bit.
23+
</pre>
24+
25+
<p><strong>Example 3:</strong></p>
26+
27+
<pre><strong>Input:</strong> n = 11111111111111111111111111111101
28+
<strong>Output:</strong> 31
29+
<strong>Explanation:</strong> The input binary string <strong>11111111111111111111111111111101</strong> has a total of thirty one '1' bits.
30+
</pre>
31+
32+
<p>&nbsp;</p>
33+
<p><strong>Constraints:</strong></p>
34+
35+
<ul>
36+
<li>The input must be a <strong>binary string</strong> of length <code>32</code>.</li>
37+
</ul>
38+
39+
<p>&nbsp;</p>
40+
<strong>Follow up:</strong> If this function is called many times, how would you optimize it?</div>

0 commit comments

Comments
 (0)