简单的二进制加法。
string addBinary(string a, string b) {
string res="";
int m = a.size()-1;
int n = b.size()-1;
int carry=0;
while(m>=0||n>=0)
{
int p=m>=0?a[m--]-'0':0; //若a数组遍历完则p赋值为0
int q=n>=0?b[n--]-'0':0; //若b数组遍历完则q赋值为0
carry+=(p+q);
res=to_string(carry%2)+res;
carry/=2;
}
return carry==1?"1"+res:res;
}