Snipp

AI ChatCreate New SnippetDiscover
No snippets yet
HomeNewDiscoverChat
Back to Snippets

pair programming

pythonCollaborativeView OnlyVersion 1
Created 3/1/2026, 7:54:07 PM • Last updated 3/1/2026, 7:54:07 PM

Code

def decodeString(s: str) -> str:
    stack = []
    current_num = 0
    current_str = ""

    for char in s:
        if char.isdigit():
            current_num = current_num * 10 + int(char)

        elif char == "[":
            stack.append([current_num, current_str])
            current_num = 0
            current_str = 0
        
        elif char == "]":
            prev_mult, prev_str = stack.pop()

            current_str = prev_str + (prev_mult * current_str)
        
        else:
            current_str += char

    return current_str