add_binary_strings namespace

Given two binary strings A and B consisting of only 0s and 1s. Find the resultant string after adding the two Binary Strings. Note: The input strings may contain leading zeros but the output string should not have any leading zeros.

Example 1:

Input: A = "1101", B = "111" Output: 10100 Explanation: 1101

  • 111 10100 Example 2:

Input: A = "10", B = "01" Output: 11 Explanation: 10

  • 01 11

URL: https://practice.geeksforgeeks.org/problems/add-binary-strings3805/1

Functions

auto add_binary(std::string A, std::string B) -> std::string
Compute the some of A and B when represented as binary strings.
static void removeTrailingCharacters(std::string& str, const char charToRemove)
static void comput_carry_and_char_from_sum(int sum, int& carry, char& digit)

Function documentation

std::string add_binary_strings::add_binary(std::string A, std::string B)

Compute the some of A and B when represented as binary strings.

Parameters
A
B
Returns string representing the sum of A and B

static void add_binary_strings::removeTrailingCharacters(std::string& str, const char charToRemove)

Parameters
str
charToRemove

static void add_binary_strings::comput_carry_and_char_from_sum(int sum, int& carry, char& digit)

Parameters
sum
carry
digit