<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:
    string addBinary(string a, string b) {
        int carry = 0;
        string ans;
        int t = 0;
        int n1=a.size(),n2=b.size();
       //*making the size same.*
        if (n1 > n2)
            while (t < n1 - n2)
                b.insert(b.begin(), '0'), t++;
        else if (n2 > n1)
            while (t < n2 - n1)
                a.insert(a.begin(), '0'), t++;
        int i=a.size()-1;
//basic addition properties of binary
        for (;i>= 0;i--) {
           int x = a[i] - '0';
            int y = b[i] - '0';
            if (x + y + carry == 3)
                ans.push_back('1'), carry = 1;
            else if (x + y + carry == 2)
                ans.push_back('0'), carry = 1;
            else if (x + y + carry == 1)
                ans.push_back('1'), carry = 0;
            else if (x + y + carry == 0)
                ans.push_back('0');
            else
             ans.push_back(x+y+carry+'0'),carry=0;
        }

        if (carry == 1)
            ans.push_back('1');
//since the answer came in reverese so reversing
        reverse(ans.begin(), ans.end()); 
        return ans;
    }
};
8200