leetcode --67. Add Binary

来源:互联网 发布:飞机大战java代码框架 编辑:程序博客网 时间:2024/05/19 00:52

题目:https://leetcode.com/problems/add-binary/tabs/description

代码:

class Solution {public:    string addBinary(string a, string b) {        int i = a.size()-1,j = b.size()-1,temp=0;        string c;        while(i>=0|j>=0|temp==1){            if(i>=0){                temp+=a[i--]-'0';            }            if(j>=0){                temp+=b[j--]-'0';            }            c+=char(temp%2+'0');            temp=temp/2;        }        reverse(c.begin(),c.end());        return c;    }};