Remove Consecutive Duplicates
Python
Medium
3 views
Problem Description
A string s is provided (no spaces). Remove consecutive duplicate characters and output result.
Output Format
One line result.
Official Solution
import sys
s=sys.stdin.read().strip()
if not s: sys.exit(0)
out=[s[0]]
for ch in s[1:]:
if ch!=out[-1]:
out.append(ch)
sys.stdout.write(''.join(out))
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!