[C++/Python] Convert from Base 2 Addition
Intuition:\nQuite similar to 1017. Convert to Base -2\n1. Maybe write a base2 addition first?\n2. Add minus -?\n3. Done.\n\n\n\n## Complexity\nTime O(N), Space 
## **Intuition**:\nQuite similar to [1017. Convert to Base -2](https://leetcode.com/problems/convert-to-base-2/discuss/265507/JavaC++Python-2-lines-Exactly-Same-as-Base-2)\n1. Maybe write a base2 addition first?\n2. Add minus `-`?\n3. Done.\n<br>\n\n\n## **Complexity**\nTime `O(N)`, Space `O(N)`\n<br>\n\n\n**C++:**\n```\n    vector<int> addBinary(vector<int>& A, vector<int>& B) {\n        vector<int> res;\n        int carry = 0, i = A.size() - 1, j = B.size() - 1;\n        while (i >= 0 || j >= 0 || carry) {\n            if (i >= 0) carry += A[i--];\n            if (j >= 0) carry += B[j--];\n            res.push_back(carry & 1);\n            carry = (carry >> 1);\n        }\n        reverse(res.begin(), res.end());\n        return res;\n    }\n\n    vector<int> addNegabinary(vector<int>& A, vector<int>& B) {\n        vector<int> res;\n        int carry = 0, i = A.size() - 1, j = B.size() - 1;\n        while (i >= 0 || j >= 0 || carry) {\n            if (i >= 0) carry += A[i--];\n            if (j >= 0) carry += B[j--];\n            res.push_back(carry & 1);\n            carry = -(carry >> 1);\n        }\n        while (res.size() > 1 && res.back() == 0)\n            res.pop_back();\n        reverse(res.begin(), res.end());\n        return res;\n    }\n```\n\n**Python:**\n```\n    def addBinary(self, A, B):\n        res = []\n        carry = 0\n        while A or B or carry:\n            carry += (A or [0]).pop() + (B or [0]).pop()\n            res.append(carry & 1)\n            carry = carry >> 1\n        return res[::-1]\n\n    def addNegabinary(self, A, B):\n        res = []\n        carry = 0\n        while A or B or carry:\n            carry += (A or [0]).pop() + (B or [0]).pop()\n            res.append(carry & 1)\n            carry = -(carry >> 1)\n        while len(res) > 1 and res[-1] == 0:\n            res.pop()\n        return res[::-1]\n```\n
[]