<commit_before>#include "AddBinary.hpp"

string AddBinary::addBinary(string a, string b)
{
  if (a.size() == 0) {
    return b;
  }

  if (b.size() == 0) {
    return a;
  }

  if (a.size() < b.size()) {
    return addBinary(b, a);
  }

  int sza = a.size();
  int szb = b.size();
  string c = "";
  int carry = 0;
  int i, j;

  for (i = sza - 1, j = szb - 1; j >= 0; i--, j--) {
    int val = a[i] - '0' + b[j] - '0' + carry;
    carry = val / 2;
    c = to_string(val % 2) + c;
  }

  for (; i >= 0; i--) {
    int val = a[i] - '0' + carry;
    carry = val / 2;
    c = to_string(val % 2) + c;
  }

  if (carry) {
    c = to_string(carry) + c;
  }

  return c;
}
<commit_msg>Refine Problem 67. Add Binary.<commit_after>#include "AddBinary.hpp"

string AddBinary::addBinary(string a, string b)
{
  string s = "";
  int c = 0, i = a.size() - 1, j = b.size() - 1;

  while (i >= 0 || j >= 0 || c == 1) {
    c += i >= 0 ? a[i--] - '0' : 0;
    c += j >= 0 ? b[j--] - '0' : 0;
    s = char(c % 2 + '0') + s;
    c /= 2;
  }

  return s;
}

{'fraction_non_alphanumeric': 0.2254335260115607, 'fraction_numerical': 0.029865125240847785, 'mean_word_length': 1.862258953168044, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4767707', 'n_tokens_mistral': 503, 'n_tokens_neox': 470, 'n_words': 135}