Run Length Decode
Python
Medium
2 views
Problem Description
An encoded string is provided like a3b2c (letters with optional number). Decode and output the original string.
Input Format
One line encoded.
Output Format
One line decoded.
Constraints
Total decoded length
Official Solution
import sys
s=sys.stdin.read().strip()
if not s: sys.exit(0)
out=[]
i=0
n=len(s)
while i<n:
ch=s[i]
i+=1
num=0
while i<n and '0'<=s[i]<='9':
num=num*10 + (ord(s[i])-48)
i+=1
if num==0:
num=1
out.append(ch*num)
res=''.join(out)
sys.stdout.write(res[:200000])
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!