Given two binary strings, return their sum (also a binary string).

For example,
a = "11"
b = "1"
Return "100".

``````/**
* @param {string} a
* @param {string} b
* @return {string}
*/
var addBinary = function(a, b) {
var num1 = a.length-1;
var num2 = b.length-1;
var bit = 0;
if (num1>=num2) {
var temp = "";
while (num2>=0) {
var result = parseInt(a[num1])+parseInt(b[num2])+bit;
if (result === 0) {
bit = 0;
temp = '0' + temp;
} else if (result === 1) {
bit = 0;
temp = '1' + temp;
} else if (result === 2) {
bit = 1;
temp = '0' + temp;
} else {
bit = 1;
temp = '1' + temp;
}
num1--;
num2--;
}
while (num1>=0) {
var result = parseInt(a[num1])+bit;
if (result === 1) {
bit = 0;
temp = '1' + temp;
} else if (result === 0) {
bit = 0;
temp = '0' + temp;
} else  {
bit = 1;
temp = '0' + temp;
}
num1--;
}
if (bit===1)
temp = '1' + temp;
return temp;
} else {
}
};
``````

``````/**
* @param {string} a
* @param {string} b
* @return {string}
*/
var addBinary = function(a, b) {
var s = "";
var c = 0;
var i = a.length - 1;
var j = b.length - 1;
while(i >= 0 || j >= 0 || c == 1)
{
c += i >= 0 ? parseInt(a[i --]) : 0;
c += j >= 0 ? parseInt(b[j --]) : 0;
s = (c % 2) + s;
c = parseInt(c / 2);
}
return s;
};
``````