67. add binary

Given two binary strings, return their sum (also a binary string).

The input strings are both non-empty and contains only characters 1 or 0.

Description

Input: a = "11", b = "1"
Output: "100"
class Solution {
public:
    string addBinary(string a, string b) {
        int alen=a.size()-1,blen=b.size()-1,c=0;//c表示的是二者相加得到的数
        string ans="";
        while(alen>=0||blen>=0||c==1)
        {
            c+=alen>=0?a[alen--]-'0':0;
            c+=blen>=0?b[blen--]-'0':0;
            ans=char(c%2+'0')+ans;
            c/=2;
        }
        return ans;
    }
};