public class Solution {
public String addBinary(String a, String b) {
char[] aa=a.toCharArray();
char[] bb=b.toCharArray();
int size=aa.length>=bb.length?aa.length:bb.length;
int[] mm=new int[size];
int c=0;
int i=aa.length-1,j=bb.length-1,k=size-1;
for(;i>=0&&j>=0;i--,j--,k--)
{
mm[k]=(aa[i]-'0'+bb[j]-'0'+c)%2;
if(aa[i]-'0'+bb[j]-'0'+c>=2) c=1;
else c=0;
}
while(i>=0)
{
mm[k]=(aa[i]-'0'+c)%2;
if(aa[i]-'0'+c>=2) c=1;
else c=0;
k--;i--;
}
while(j>=0)
{
mm[k]=(bb[j]-'0'+c)%2;
if(bb[j]-'0'+c>=2) c=1;
else c=0;
k--;j--;
}
String s="";
if(c==1)
s+=String.valueOf(c);
for(int n=0;n<mm.length;n++)
s=s+String.valueOf(mm[n]);
return s;
}
}