<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 n=a.size();
        int m=b.size();
        
        int count=0;
        string ans;
        while(n>0 && m>0)
        {
            if(a[n-1]=='1' && b[m-1]=='1')
            {
                if(count==0)
                {
                   ans='0'+ans;
                    
                }
                else
                {
                    ans='1'+ans;
                    
                }
                count=1;
            }
            else if(a[n-1]=='0' && b[m-1]=='0')
            {
                if(count==1)
                {
                   ans='1'+ans;
                    
                }
                else
                {
                    ans='0'+ans;
                    
                }
                count=0;
            }
            else
            {
                if(count==1)
                {
                   ans='0'+ans;
                    count=1;
                    
                }
                else
                {
                    ans='1'+ans;
                    count=0;
                    
                }
                
            }
            n--;
            m--;
        }
        
        cout<<n<<m<<endl;
        
        while(n>0)
        {
            if(count==1 && a[n-1]=='1')
            {
                ans='0'+ans;
                count=1;
                
            }
            else if(count==1 && a[n-1]=='0')
            {
                ans='1'+ans;
                count=0;
            }
            else
            {
                ans=a[n-1]+ans;
            }
            n--;
        }
        
        while(m>0)
        {
            if(count==1 && b[m-1]=='1')
            {
                ans='0'+ans;
                count=1;
                
            }
            else if(count==1 && b[m-1]=='0')
            {
                ans='1'+ans;
                count=0;
            }
            else
            {
                ans=b[m-1]+ans;
            }
            m--;
        }
        
        if(count==1)
            ans='1'+ans;
        
        return ans;
        
        
    }
};
11400