Class Solution

java.lang.Object
g1001_1100.s1017_convert_to_base_2.Solution

public class Solution extends Object
1017 - Convert to Base -2.<p>Medium</p> <p>Given an integer <code>n</code>, return <em>a binary string representing its representation in base</em> <code>-2</code>.</p> <p><strong>Note</strong> that the returned string should not have leading zeros unless the string is <code>&quot;0&quot;</code>.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> n = 2</p> <p><strong>Output:</strong> &ldquo;110&rdquo; <strong>Explantion:</strong> (-2)<sup>2</sup> + (-2)<sup>1</sup> = 2</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> n = 3</p> <p><strong>Output:</strong> &ldquo;111&rdquo; <strong>Explantion:</strong> (-2)<sup>2</sup> + (-2)<sup>1</sup> + (-2)<sup>0</sup> = 3</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> n = 4</p> <p><strong>Output:</strong> &ldquo;100&rdquo; <strong>Explantion:</strong> (-2)<sup>2</sup> = 4</p> <p><strong>Constraints:</strong></p> <ul> <li><code>0 <= n <= 10<sup>9</sup></code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • baseNeg2

      public String baseNeg2(int n)