#67Add Binary
Easy
→
Approach:
Intuition
The goal is to add two given string a and b, which represent the numbers in binary. We can think of it as two row of digits, add each column from the right to left, keep track the carry bit (like 1 + 1 results in 0 and carry 1 to the next row) and build the result string step by step.
Implementation
| |
Complexity Analysis
- Time complexity: $O(\max(n, m))$ where $n$ and $m$ are the lengths of
aandbrespectively. We traverse each string at most once. - Space complexity: $O(\max(n, m))$ for storing the result.