LeetCode Question: 67. Add Binary ( Level : Easy ) Problem Statement: Given two binary strings a and b , return their sum as a binary string. Note :- Scroll horizontally to see the full line of code. class Solution { public : string addBinary ( string a , string b ) { int n = a . length () - 1 ; int m = b . length () - 1 ; string ans ; int c = 0 ; while ( m > - 1 && n > - 1 ) { int a1 = int ( a [ n ]) - 48 , b1 = int ( b [ m ]) - 48 ; int sum = a1 ^ b1 ^ c ; c = ( a1 & b1 ) | ( a1 & c ) | ( b1 & c ); ans . append ( to_string ( sum )); n -- ; m -- ; } while ( n > - 1 ) { int a1 = int ( a [ n ]) - 48 ; int sum = a1 ^ c ; c = a1 & c ; ans . append ( to_string ( sum )); ...
Dive into the dynamic world of technology with Space of Coders. Explore Computer Science, C++, JavaScript, Web Development, Data Science, AI, and Blockchain. Elevate your skills through insightful programming tips, and cybersecurity strategies, and stay ahead of the curve with the latest tech trends. Your ultimate destination for mastering the digital landscape awaits!