leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

0067.cpp (444B)


0 class Solution {
1 public:
2 string addBinary(string a, string b) {
3 string res;
4 int i = a.size() - 1;
5 int j = b.size() - 1;
6 int add = 0;
7 while (i >= 0 || j >= 0 || add) {
8 if (i >= 0) add += a[i--] - '0';
9 if (j >= 0) add += b[j--] - '0';
10 res += to_string(add % 2);
11 add /= 2;
12 }
13 reverse(res.begin(), res.end());
14 return res;
15 }
16 };