public static String addBinary(String a, String b) {//AC after consulting
        if (a == null) return b;
        if (b == null) return a;
        String ret = "";
        int carry = 0;
        for (int i = a.length()-1, j = b.length()-1; i >=0 || j >= 0; --i, --j) {
            int tempa = i>=0 ? a.charAt(i)-'0': 0;
            int tempb = j>=0 ? b.charAt(j)-'0': 0;
            int temp = tempa + tempb + carry;
            carry = temp/2;
            ret += temp%2;
        }
        if (carry == 1) ret += '1';
        String reverse = new StringBuffer(ret).reverse().toString();
        //System.out.println(ret);
        return reverse;
    }