java.lang.Object
g1001_1100.s1009_complement_of_base_10_integer.Solution

public class Solution extends Object
1009 - Complement of Base 10 Integer.<p>Easy</p> <p>The <strong>complement</strong> of an integer is the integer you get when you flip all the <code>0</code>&rsquo;s to <code>1</code>&rsquo;s and all the <code>1</code>&rsquo;s to <code>0</code>&rsquo;s in its binary representation.</p> <ul> <li>For example, The integer <code>5</code> is <code>&quot;101&quot;</code> in binary and its <strong>complement</strong> is <code>&quot;010&quot;</code> which is the integer <code>2</code>.</li> </ul> <p>Given an integer <code>n</code>, return <em>its complement</em>.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> n = 5</p> <p><strong>Output:</strong> 2</p> <p><strong>Explanation:</strong> 5 is &ldquo;101&rdquo; in binary, with complement &ldquo;010&rdquo; in binary, which is 2 in base-10.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> n = 7</p> <p><strong>Output:</strong> 0</p> <p><strong>Explanation:</strong> 7 is &ldquo;111&rdquo; in binary, with complement &ldquo;000&rdquo; in binary, which is 0 in base-10.</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> n = 10</p> <p><strong>Output:</strong> 5</p> <p><strong>Explanation:</strong> 10 is &ldquo;1010&rdquo; in binary, with complement &ldquo;0101&rdquo; in binary, which is 5 in base-10.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>0 <= n < 10<sup>9</sup></code></li> </ul> <p><strong>Note:</strong> This question is the same as 476: <a href="https://leetcode.com/problems/number-complement/" target="_top">https://leetcode.com/problems/number-complement/</a></p>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • bitwiseComplement

      public int bitwiseComplement(int n)