Given two binary strings a
and b
, return their sum as a binary string.
Example
Input: a = "11", b = "1"
Output: "100"
Solution
/**
* @param {string} a
* @param {string} b
* @return {string}
*/
var addBinary = function(a, b) {
//Add a and b as binary numbers
return (BigInt(`0b${a}`) + BigInt(`0b${b}`)).toString(2);
};