https://leetcode.com/problems/add-binary/description/
class Solution {public: string addBinary(string a, string b) { string res; int carry = 0; for (int ia = a.length() - 1, ib = b.length() - 1; ia >= 0 || ib >= 0; ia--, ib--) { int ca = ia < 0 ? 0 : a[ia] - '0'; int cb = ib < 0 ? 0 : b[ib] - '0'; int c = ca + cb + carry; res.push_back(c % 2 + '0'); carry = c / 2; } if (carry > 0) res.push_back(carry + '0'); reverse(res.begin(), res.end()); return res; }};