Given two binary strings, return their sum (also a binary string).
For example,
a = "11"
b = "1"
Return "100"
.
简单的二进制高精度加法。
class Solution {
public:
string addBinary(string a, string b) {
string ans="";
int c=,i=a.length()-,j=b.length()-;
while(i>=||j>=||c>)
{
c+= i>=? a[i--]-'':;
c+= j>=? b[j--]-'':;
ans=char(c%+'') + ans;
c/=;
}
return ans;
}
};