Binary XOR
Python
Medium
3 views
Problem Description
Two binary strings a and b are provided (same length). Compute bitwise XOR and output result without leading zeros (output 0 if all zero).
Input Format
Two lines: a then b.
Output Format
One binary string.
Official Solution
import sys
lines=sys.stdin.read().splitlines()
if len(lines)<2:
sys.exit(0)
a=lines[0].strip()
b=lines[1].strip()
out=[]
for i in range(len(a)):
out.append('0' if a[i]==b[i] else '1')
res=''.join(out).lstrip('0')
sys.stdout.write(res if res else '0')
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!