public String addBinary(String a, String b) {
        StringBuilder result = new StringBuilder();
        a = new StringBuilder(a).reverse().toString();
        b = new StringBuilder(b).reverse().toString();

        int index = 0;
        int extra = 0;
        while(index < a.length() || index < b.length()) {
            int first = index < a.length() ? Character.getNumericValue(a.charAt(index)) : 0;
            int second = index < b.length() ? Character.getNumericValue(b.charAt(index)) : 0;
            int digit = (first + second + extra) % 2;
            extra = first + second + extra >= 2 ? 1 : 0;
            result.append(digit);
            index++;
        }

        if(extra == 1)
            result.append(1);

        return result.reverse().toString();
    }