Expression Expand (Ladder)
Description
Given an expression s includes numbers, letters and brackets. Number represents the number of repetitions inside the brackets(can be a string or another expression).Please expand expression to be a string.
Example s = abc3[a] return abcaaa s = 3[abc] return abcabcabc s = 4[ac]dy, return acacacacdy s = 3[2[ad]3[pf]]xyz, return adadpfpfpfadadpfpfpfadadpfpfpfxyz
Challenge: Can you do it without recursion? we are here
Assumption
- "[]" buckets are right appearence
- number/[]/char are perfect and no mistake
- known data format
Link
Method
- DFS/double pointers with Stack
- backTracking with recursion
Example
- 1
code
Similar problems
calculator, parse JSON
Tags
Divide and Conquer, Recursion, Stack, Non Recursion,
Yahoo