백준 9935 - 문자열 폭발


백준 9935 - 문자열 폭발

123456789101112131415161718import sys txt = sys.stdin.readline().rstrip()b = list(sys.stdin.readline().rstrip())stack = [] for t in txt: stack.append(t) if len(stack) < len(b): continue if stack[-len(b):] == b: del stack[-len(b):] if stack: print("".join(stack)) else: print("FRULA") Colored by Color Scriptercs 처음에는 while과 find()로 index위치를 찾아 제거하는 형태로 작성했으나 시간초과. 두번째 stack을 사용하며 string slicing하여 스택을 초기화 하는 형태로 작성했으나 이 또한 시간초과세번째 stack을 사용하며 문자를 list화 하여 del 하는 방식으로 해결...



원문링크 : 백준 9935 - 문자열 폭발