/** * @param {string} a * @param {string} b * @return {string} */ var addBinary = function(a, b) { let x = parseInt(a, 2) let y = parseInt(b, 2) let res let carry while (y) { res = x ^ y carry = (x & y) << 1 x = res y = carry } return x.toString(2) }
classSolution: defaddBinary(self, a, b) -> str: x, y = int(a, 2), int(b, 2) while y: x, y = x ^ y, (x & y) << 1 returnbin(x)[2:]