[JavaScript] 1073. Adding Two Negabinary Numbers
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\nTrial & error to get below:\n-1 => reminder is 1 and carry is 1\n\n# Comp
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\nTrial & error to get below:\n`-1 => reminder is 1 and carry is 1`\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nvar addNegabinary = function (a1, a2) {\n  const ans = []\n  ans.push_front = ans.unshift\n  ans.pop_front = ans.shift\n  const m = a1.length\n  const n = a2.length\n  var carry = 0\n  for (var i = m - 1, j = n - 1; i >= 0 || j >= 0; i--, j--) {\n    const sum = (a1[i] || 0) + (a2[j] || 0) + carry\n    let reminder = sum % -2\n    carry = Math.trunc(sum / -2)\n    if (reminder === -1) {\n      reminder = 1\n      carry = 1\n    }\n    ans.push_front(reminder)\n  }\n  if (carry === 1) {\n    ans.push_front(carry)\n  } else if (carry === -1) {\n    ans.push_front(1, 1)\n  }\n  while (ans[0] === 0 && ans.length > 1) {\n    ans.pop_front()\n  }\n  return ans\n}\n\n```
['JavaScript']