9
9
* calculates the sum. If the sum exceeds 1, a carry is generated for the next
10
10
* bit. The results for each bit are collected in a result string, which is
11
11
* reversed at the end to present the final binary sum correctly. Additionally,
12
- * the function validates the input to ensure that only valid binary strings
13
- * (containing only '0' and '1') are processed. If invalid input is detected,
12
+ * the function validates the input to ensure that only valid binary strings
13
+ * (containing only '0' and '1') are processed. If invalid input is detected,
14
14
* it returns an empty string.
15
15
* @author [Muhammad Junaid Khalid](https://github.com/mjk22071998)
16
16
*/
@@ -35,12 +35,13 @@ class BinaryAddition {
35
35
*
36
36
* @param a The first binary string.
37
37
* @param b The second binary string.
38
- * @return The sum of the two binary strings as a binary string, or an empty string
39
- * if either input string contains non-binary characters.
38
+ * @return The sum of the two binary strings as a binary string, or an empty
39
+ * string if either input string contains non-binary characters.
40
40
*/
41
41
std::string addBinary (const std::string& a, const std::string& b) {
42
42
if (!isValidBinaryString (a) || !isValidBinaryString (b)) {
43
- return " " ; // Return empty string if input contains non-binary characters
43
+ return " " ; // Return empty string if input contains non-binary
44
+ // characters
44
45
}
45
46
46
47
std::string result;
@@ -73,9 +74,8 @@ class BinaryAddition {
73
74
* @return true if the string is binary, false otherwise.
74
75
*/
75
76
bool isValidBinaryString (const std::string& str) const {
76
- return std::all_of (str.begin (), str.end (), [](char c) {
77
- return c == ' 0' || c == ' 1' ;
78
- });
77
+ return std::all_of (str.begin (), str.end (),
78
+ [](char c) { return c == ' 0' || c == ' 1' ; });
79
79
}
80
80
};
81
81
} // namespace greedy_algorithms
0 commit comments