You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<h2><ahref="https://leetcode.com/problems/number-complement">Number Complement</a></h2> <imgsrc='https://img.shields.io/badge/Difficulty-Easy-brightgreen'alt='Difficulty: Easy' /><hr><p>The <strong>complement</strong> of an integer is the integer you get when you flip all the <code>0</code>'s to <code>1</code>'s and all the <code>1</code>'s to <code>0</code>'s in its binary representation.</p>
2
+
3
+
<ul>
4
+
<li>For example, The integer <code>5</code> is <code>"101"</code> in binary and its <strong>complement</strong> is <code>"010"</code> which is the integer <code>2</code>.</li>
5
+
</ul>
6
+
7
+
<p>Given an integer <code>num</code>, return <em>its complement</em>.</p>
8
+
9
+
<p> </p>
10
+
<p><strongclass="example">Example 1:</strong></p>
11
+
12
+
<pre>
13
+
<strong>Input:</strong> num = 5
14
+
<strong>Output:</strong> 2
15
+
<strong>Explanation:</strong> The binary representation of 5 is 101 (no leading zero bits), and its complement is 010. So you need to output 2.
16
+
</pre>
17
+
18
+
<p><strongclass="example">Example 2:</strong></p>
19
+
20
+
<pre>
21
+
<strong>Input:</strong> num = 1
22
+
<strong>Output:</strong> 0
23
+
<strong>Explanation:</strong> The binary representation of 1 is 1 (no leading zero bits), and its complement is 0. So you need to output 0.
24
+
</pre>
25
+
26
+
<p> </p>
27
+
<p><strong>Constraints:</strong></p>
28
+
29
+
<ul>
30
+
<li><code>1 <= num < 2<sup>31</sup></code></li>
31
+
</ul>
32
+
33
+
<p> </p>
34
+
<p><strong>Note:</strong> This question is the same as 1009: <ahref="https://leetcode.com/problems/complement-of-base-10-integer/"target="_blank">https://leetcode.com/problems/complement-of-base-10-integer/</a></p>
0 commit comments