1、
i>=0||j>=0这里一方到头另一方继续,少的加0
class Solution {
public:
string addBinary(string a, string b) {
string res;
int carry = 0;
int x,y;
int i = a.size()-1;
int j = b.size()-1;
for(;i >=0 || j >= 0; i--, j--)
{
x = i >= 0 ? a[i] - '0':0;
y = j >= 0 ? b[j] - '0':0;
//x = a[i] - '0'; y = a[j] - '0';
res+=(x+y+carry)%2 + '0';
carry = (x+y+carry)/2;
}
if(carry) res+='1';
reverse(res.begin(),res.end());
return res;
}
};