LeetCode 394. Decode String

preview_player
Показать описание

Рекомендации по теме
Комментарии
Автор

Thanks for this explanation. I have seen others where input string is broken into and there is special processing for (pre) part. This one is easier. Line 3 (stack = [[1, ""]]) also converts the (pre) part to (multiplier) and (repeat_string) where multiplier is 1 and repeat_string = pre, so that the whole string can be broken down into a series of (multiplier) and (repeat_string) and we apply the same logic everywhere.
You mentioned LC 726 (Num of atoms) and calculators (LC 224, 227, 772) as examples of parsing that can be solved either via recursion or a stack; another parsing LC problem is LC 736 (Parse LISP expression). And opposite of this problem is LC 443 (Compress in place).

anant