package leetcode;

import java.util.Arrays;

/**
 * https://leetcode.com/problems/adding-two-negabinary-numbers/
 */
public class Problem1073 {
    public int[] addNegabinary(int[] arr1, int[] arr2) {
        // TODO
        return null;
    }

    public static void main(String[] args) {
        Problem1073 prob = new Problem1073();
        System.out.println(Arrays.toString(prob.addNegabinary(new int[]{1, 1, 1, 1, 1}, new int[]{1, 0, 1}))); // [1,0,0,0,0]
        System.out.println(Arrays.toString(prob.addNegabinary(new int[]{1, 1, 1, 1, 1}, new int[]{1, 0, 1, 1}))); // [1,1,0]
    }
}

@@ -34,17 +34,68 @@
 il.Array
-s
+List;%0Aimport java.util.Arrays;%0Aimport java.util.List
 ;%0A%0A/**%0A 
@@ -257,35 +257,1788 @@
     
-// TODO%0A        return null
+List%3CInteger%3E list = new ArrayList%3C%3E();%0A        int i = arr1.length - 1;%0A        int j = arr2.length - 1;%0A        boolean positive = true;%0A        int carry = 0;%0A        while (i %3E= 0 && j %3E= 0) %7B%0A            if (positive) %7B%0A                int sum = arr1%5Bi%5D + arr2%5Bj%5D + carry;%0A                carry = sum / 2;%0A                list.add(sum %25 2);%0A                positive = false;%0A            %7D else %7B%0A                int sum = -(arr1%5Bi%5D + arr2%5Bj%5D) + carry;%0A                carry = sum / 2;%0A                list.add(Math.abs(sum %25 2));%0A                positive = true;%0A            %7D%0A            i--;%0A            j--;%0A        %7D%0A        while (i %3E= 0) %7B%0A            if (positive) %7B%0A                int sum = arr1%5Bi%5D + carry;%0A                carry = sum / 2;%0A                list.add(sum %25 2);%0A                positive = true;%0A            %7D else %7B%0A                int sum = -arr1%5Bi%5D + carry;%0A                carry = sum / 2;%0A                list.add(Math.abs(sum %25 2));%0A                positive = false;%0A            %7D%0A            i--;%0A        %7D%0A        while (j %3E= 0) %7B%0A            if (positive) %7B%0A                int sum = arr2%5Bj%5D + carry;%0A                carry = sum / 2;%0A                list.add(Math.abs(sum %25 2));%0A                positive = true;%0A            %7D else %7B%0A                int sum = -arr2%5Bj%5D + carry;%0A                carry = sum / 2;%0A                list.add(Math.abs(sum %25 2));%0A                positive = false;%0A            %7D%0A            j--;%0A        %7D%0A        int size = list.size();%0A        int k = list.size() - 1;%0A        while (k %3E= 0 && list.get(k) == 0) %7B%0A            k--;%0A            size--;%0A        %7D%0A        int%5B%5D answer = new int%5Bsize%5D;%0A        int l = 0;%0A        for (; k %3E= 0; k--) %7B%0A            answer%5Bl++%5D = list.get(k);%0A        %7D%0A        return answer
 ;%0A  
@@ -2129,24 +2129,26 @@
 blem1073();%0A
+//
         Syst
@@ -2257,24 +2257,26 @@
 %5B1,0,0,0,0%5D%0A
+//
         Syst
@@ -2388,16 +2388,168 @@
 %5B1,1,0%5D%0A
+        System.out.println(Arrays.toString(prob.addNegabinary(new int%5B%5D%7B1, 1, 1, 1, 1, 0, 1%7D, new int%5B%5D%7B1, 0, 1, 1, 1, 1, 0%7D))); // %5B1,1,0,0,0,1,0,1,1%5D%0A
     %7D%0A%7D%0A

Update problem 1073