java.lang.Object
g1001_1100.s1073_adding_two_negabinary_numbers.Solution

public class Solution extends Object
1073 - Adding Two Negabinary Numbers.<p>Medium</p> <p>Given two numbers <code>arr1</code> and <code>arr2</code> in base <strong>-2</strong> , return the result of adding them together.</p> <p>Each number is given in <em>array format</em>: as an array of 0s and 1s, from most significant bit to least significant bit. For example, <code>arr = [1,1,0,1]</code> represents the number <code>(-2)^3 + (-2)^2 + (-2)^0 = -3</code>. A number <code>arr</code> in <em>array, format</em> is also guaranteed to have no leading zeros: either <code>arr == [0]</code> or <code>arr[0] == 1</code>.</p> <p>Return the result of adding <code>arr1</code> and <code>arr2</code> in the same format: as an array of 0s and 1s with no leading zeros.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> arr1 = [1,1,1,1,1], arr2 = [1,0,1]</p> <p><strong>Output:</strong> [1,0,0,0,0]</p> <p><strong>Explanation:</strong> arr1 represents 11, arr2 represents 5, the output represents 16.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> arr1 = [0], arr2 = [0]</p> <p><strong>Output:</strong> [0]</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> arr1 = [0], arr2 = [1]</p> <p><strong>Output:</strong> [1]</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= arr1.length, arr2.length <= 1000</code></li> <li><code>arr1[i]</code> and <code>arr2[i]</code> are <code>0</code> or <code>1</code></li> <li><code>arr1</code> and <code>arr2</code> have no leading zeros</li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • addNegabinary

      public int[] addNegabinary(int[] arr1, int[] arr2)