Expand Decimal Digits into Runs of Ones
Problem statement
Scan text from left to right. Replace each decimal digit d with exactly d copies of the character 1. Keep every nondigit character unchanged.
Each digit is interpreted independently, so 0 contributes no characters.
Function
expandDigitsToOnes(text: String) → StringExamples
Example 1
text = "a5b3de"return = "a11111b111de"Each digit expands independently while letters remain in place.
Example 2
text = "x0y2"return = "xy11"Zero contributes an empty run and two contributes two ones.
Constraints
0 <= text.length <= 100000textcontains ASCII letters and decimal digits.