#67.Add Binary [LeetCode Grind 75 in Java]
[Problem Link] https://leetcode.com/problems/add-binary/
class Solution {
public String addBinary(String a, String b) {
int ptra = a.length() - 1;
int ptrb = b.length() - 1;
StringBuilder ans = new StringBuilder();
int carry = 0;
while(ptra >= 0 || ptrb >= 0){
int sum = carry;
if(ptra >= 0) sum += a.charAt(ptra --) - '0';
if(ptrb >= 0) sum += b.charAt(ptrb --) - '0';
carry = (sum > 1) ? 1 : 0;
ans.append(sum % 2);
}
if(carry != 0) ans.append(carry);
return ans.reverse().toString();
}
}