<jupyter_start><jupyter_text>Decode String（解码字符串）[@mjd507][1] ｜ [WeChat Channel（微信公众号）][2]![Logo](images/Day71-1.png)[1]: https://github.com/mjd507[2]: https://mp.weixin.qq.com/s/6xGMjn-yqJAyLexaDfFKnQ Given a string with a certain rule: `k[string]` should be expanded to `string` $k$ times. So for example, `3[abc]` should be expanded to `abcabcabc`. Nested expansions can happen, so `2[a2[b]c]` should be expanded to `abbcabbc`. 给定一个遵循特定规则的字符串：`k[string]`需要被转换为`string`重复$k$次。所以，字符串`3[abc]`应该被展开为`abcabcabc`。嵌套表达式有可能出现，所以`2[a2[b]c]`应该被展开为`abbcabbc`。  Starting Point（初始模板）<jupyter_code>def decodeString(s: str) -> str:
    stack = ['']
    for char in s:
        if char.isdigit():
            if type(stack[-1]) == str: 
                stack.append(int(char))
            else:
                stack[-1] = 10 * stack[-1] + int(char)
        elif char == '[':
            stack.append('')
        elif char == ']':
            substr = stack.pop()
            repeats = stack.pop()
            stack[-1] += (substr * repeats)
        else:
            stack[-1] += char
    return stack[0]<jupyter_output><empty_output><jupyter_text>Test Cases（测试样例）<jupyter_code>decodeString('3[a12[b]8[c]]')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.17320261437908496, 'fraction_numerical': 0.026143790849673203, 'mean_word_length': 3.2387543252595155, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 10, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '103469', 'license': 'MIT', 'n_tokens_mistral': 524, 'n_tokens_neox': 528, 'n_words': 81, 'path': 'March/Week11/71.ipynb', 'repo_name': 'Dragon1573/Daily-Problem', 'size': '1224'}