<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 m=a.length()-1;
       int n=b.length()-1;
       string ans;
       int carry=0;
       while(m>=0&&n>=0)
       {
           int s1=a[m]-'0';
           int s2=b[n]-'0';
            cout<<s1<<s2<<carry<<endl;
            cout<<s1+s2+carry<<endl;
           switch(s1+s2+carry)
           {    
               case 0: ans='0'+ans; carry=0; m--; n--; 
               break;
               case 1: ans='1'+ans; carry=0; m--; n--; 
               break;
               case 2: ans='0'+ans; carry=1; m--; n--; 
               break;
               case 3: ans='1'+ans;  carry=1; m--; n--; 
               break;
           }

       } 
       while(m>=0)
       {     int s1=a[m]-'0';
           
              switch(s1+carry){
               case 0: ans='0'+ans; m--;  carry=0;
               break;
               case 1: ans='1'+ans; m--; carry=0;
               break;
               case 2: ans='0'+ans; m--;  carry=1;
               break;
              }
       }

       while(n>=0)
       {     int s2=b[n]-'0';
             
              switch(s2+carry){
               case 0: ans='0'+ans;  n--; carry=0;
               break;
               case 1: ans='1'+ans;  n--; carry=0;
               break;
               case 2: ans='0'+ans; n--; carry=1;
               break;
              }
       }
       if(carry==1) {ans='1'+ans;}
      return ans;
    }
};
11500