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

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

class Solution {
public:
string addBinary(string a, string b) {
int lena=a.length();
int lenb=b.length();
if(lena==0){
return b;
}
if(lenb==0){
return a;
}
int count=0;
if(lena<lenb){
string tmp=a;
a=b;
b=tmp;
int tmp1=lena;
lena=lenb;
lenb=tmp1;
}

for(int i=lenb-1,j=lena-1;i>=0;i--,j--){
if(count==0){
if((a[j]=='1')&&(b[i]=='1')){
a[j]='0';
count=1;
}
else if((a[j]=='1')||(b[i]=='1')){
a[j]='1';
count=0;
}
}
else{

if((a[j]=='1')&&(b[i]=='1')){
a[j]='1';
count=1;
}
else if((a[j]=='1')||(b[i]=='1')){
a[j]='0';
count=1;
}
else{
a[j]='1';
count=0;
}
}
}
for(int i=lena-lenb-1;i>=0;i--){
if(count==1){
if(a[i]=='1'){
a[i]='0';
}
else{
a[i]='1';
count =0;
}
}
else{
break;
}
}
if(count==1){
a='1'+a;
}

return a;
}
};

class Solution {
public:
string addBinary(string a, string b) {
int lena=a.length();
int lenb=b.length();
if(lena==0){
return b;
}
if(lenb==0){
return a;
}
int count=0;
if(lena<lenb){
string tmp=a;
a=b;
b=tmp;
int tmp1=lena;
lena=lenb;
lenb=tmp1;
}
int sum=0;
for(int i=lenb-1,j=lena-1;i>=0;i--,j--){

sum=a[j]-'0'+b[i]-'0'+count;
if(sum==1){
a[j]='1';
count=0;;
}
else if(sum==2){
a[j]='0';
count=1;
}else if(sum==3){
a[j]='1';
count=1;
}

}
for(int j=lena-lenb-1;j>=0;j--){
sum=a[j]-'0'+count;
if(sum==0){
count=0;
break;
}
else if(sum==1){
a[j]='1';
count=0;
break;
}
else if(sum==2){
a[j]='0';
count=1;
}
}
if(count==1){
a='1'+a;
}

return a;
}
};