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:/
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)
#include <source/add_binary_strings.cpp>
| Parameters | |
|---|---|
| str | |
| charToRemove | |
static void add_ binary_ strings:: comput_carry_and_char_from_sum(int sum,
int& carry,
char& digit)
#include <source/add_binary_strings.cpp>
| Parameters | |
|---|---|
| sum | |
| carry | |
| digit | |