Class Solution
java.lang.Object
g0401_0500.s0476_number_complement.Solution
476 - Number Complement.<p>Easy</p>
<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>
<ul>
<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>
</ul>
<p>Given an integer <code>num</code>, return <em>its complement</em>.</p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> num = 5</p>
<p><strong>Output:</strong> 2</p>
<p><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.</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> num = 1</p>
<p><strong>Output:</strong> 0</p>
<p><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.</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= num < 2<sup>31</sup></code></li>
</ul>
<p><strong>Note:</strong> This question is the same as 1009: <a href="https://leetcode.com/problems/complement-of-base-10-integer/" target="_top">https://leetcode.com/problems/complement-of-base-10-integer/</a></p>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
findComplement
public int findComplement(int num)
-