<p>Given two binary strings <code>a</code> and <code>b</code>, return <em>their sum as a binary string</em>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<pre><strong>Input:</strong> a = "11", b = "1"
<strong>Output:</strong> "100"
</pre><p><strong class="example">Example 2:</strong></p>
<pre><strong>Input:</strong> a = "1010", b = "1011"
<strong>Output:</strong> "10101"
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= a.length, b.length &lt;= 10<sup>4</sup></code></li>
	<li><code>a</code> and <code>b</code> consist&nbsp;only of <code>&#39;0&#39;</code> or <code>&#39;1&#39;</code> characters.</li>
	<li>Each string does not contain leading zeros except for the zero itself.</li>
</ul>

class Solution {
public:
    int intC(char c) {
        return c-'0';
    }
    string addBi(string a, string b) {
        string ret;
        int n = b.size()-1;
        int m = a.size()-1;
        int tmp = 0;
        int i = 0;
        while (i <= n) {
            int tmpNum = intC(a[m-i]) + intC(b[n-i]) + tmp;
            if (tmpNum > 1) {
                tmp = 1;
                tmpNum -= 2;
            } else {
                tmp = 0;
            }
            ret += (char)(tmpNum + '0');
            i++;
        }
        while (i <= m) {
            int tmpNum = intC(a[m-i]) + tmp;
            if (tmpNum > 1) {
                tmp = 1;
                tmpNum -= 2;
            } else {
                tmp = 0;
            }
            ret += (char)(tmpNum + '0');
            i++;
        }
        if (tmp) ret += (char)(tmp + '0');
        reverse(ret.begin(), ret.end());
        return ret;
    }
    string addBinary(string a, string b) {
        string ans;
        if (a.size() > b.size()) ans = addBi(a,b);
        else ans = addBi(b,a);
        return ans;
    }
};
8600