Function that takes in two binary strings and returns their sum (also a binary string).
Approach:
1. Reverse the strings, and pad the smaller string so that length of the strings are equal.
2. Calculate the binary sum by reading each character of the string starting from index 0 and keeping track of the carry.
3. Reverse the resultant string to get the final binary string sum.
Code (*edge cases are not handled):
Approach:
1. Reverse the strings, and pad the smaller string so that length of the strings are equal.
2. Calculate the binary sum by reading each character of the string starting from index 0 and keeping track of the carry.
3. Reverse the resultant string to get the final binary string sum.
Code (*edge cases are not handled):
No comments:
Post a Comment