67. Add Binary

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

For example,
a = "11"
b = "1"
Return "100"

  • improved
class Solution {
public:
    string addBinary(string a, string b) {
        reverse(a.begin(),a.end());
        reverse(b.begin(),b.end());
        int carry = 0;
        string s="";
        int n = max(a.size(),b.size());
        for(int i = 0 ; i < n ;i++)
        {
            if(i

你可能感兴趣的:(67. Add Binary)