class Solution {
public:
string addBinary(string a, string b) {
string res;
int carry = 0;
int n = a.size(),m = b.size();
for(int i = a.size()-1,j=b.size()-1;i>=0 || j>=0;i--,j--){
int t1 = i < 0 ? 0 : (a[i] - '0');
int t2 = j < 0 ? 0 : (b[j] - '0');
int s = t1+t2+carry;
int u = s % 2;
res = to_string(u) + res;
carry = s /= 2;
}
if(carry){
res = "1"+res;
}
return res;
}
};