<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,sum=0,p=0;
        string s;
        int i=a.length()-1,j=b.length()-1;

        while(i>=0&&j>=0){
            sum=carry+int(a[i])+int(b[j])-96;
            if(sum<2){
                carry=0;
                s+=to_string(sum);
            }
            else if(sum==2)
            {
                carry=1;
                s+="0";
            }
            else
            {
                carry=1;
                s+="1";
            }
            i--;
            j--;
        }
        if(i<0){
            i=j;
            p=1;
        }
        while(i>=0)
        {
            if(p)
            {
            sum=carry+int(b[i])-48;
                if(sum<2)
                {
                    s+=to_string(sum);
                    carry=0;
                }
                else if(sum==2)
                {
                    carry=1;
                    s+="0";
                }
                else
                {
                    carry=0;
                    s+=b[i];
                }
            }
            else
                {
                
            sum=carry+int(a[i])-48;

                if(sum<2)
                {
                    s+=to_string(sum);
                    carry=0;
                }
                else if(sum==2)
                {
                    carry=1;
                    
                    s+="0";
                }
                else
                {
                    carry=0;
                    s+=a[i];
                }
            }
            i--;
        }
        if(carry)
            s+="1";
        reverse(s.begin(), s.end());
        return s;
    }
};
9900