Skip to content

Conversation

Sujalgupta2p
Copy link

🧩 Add Binary β€” LeetCode Problem 67 (C++)

πŸ“˜ Problem Description

This program adds two binary strings and returns their sum as a binary string.

The logic simulates manual binary addition β€” moving from the least significant bit (rightmost) to the most significant bit (leftmost), while carrying over when necessary.
This implementation focuses on string manipulation, bit logic, and carry handling, making it an excellent problem for improving algorithmic reasoning in C++.


🧠 How It Works

  1. Start from the end of both binary strings a and b.
  2. Add corresponding bits and a carry (initially 0).
  3. Append the result of (sum % 2) to a string.
  4. Update carry = sum / 2.
  5. Reverse the final string since addition proceeds right-to-left.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant