result
to store the final output and an empty string stack
to keep track of the current sequence of numbers.stack
for each character.stack
and append it to result
, then clear stack
.stack
is not empty, reverse it and append to result
.result
as the final answer.