public class Solution {
public String addBinary(String a, String b) {
if (a.length() < b.length()) {
String tmp = a;
a = b;
b = tmp;
}
int pa = a.length() - 1, pb = b.length() - 1;
int carrier = 0;
String rst = "";
while (pb >= 0) {
int sum = carrier + (int)(a.charAt(pa) - '0') + (int)(b.charAt(pb) - '0');
rst = String.valueOf(sum % 2) + rst;
carrier = sum / 2;
pa--;
pb--;
}
while (pa >= 0) {
int sum = carrier + (int)(a.charAt(pa) - '0');
rst = String.valueOf(sum % 2) + rst;
carrier = sum / 2;
pa--;
}
if (carrier == 1) {
rst = "1" + rst;
}
return rst;
}
}