표 편집
210708
def solution(n, k, cmd):
lst = ["O"] * n
top = n-1
remove = []
for c in cmd:
if c == "C":
remove.append(k)
lst[k] = "X"
drt = 2 * (top != k) - 1
while lst[k+drt] == "X":
k += drt
k += drt
while lst[top] == "X":
top -= 1
elif c == "Z":
idx = remove.pop()
lst[idx] = "O"
top = max(idx, top)
else:
move, steps = c.split()
steps = int(steps)
drt = 2 * (move == "D") - 1
while steps:
k += drt
steps -= lst[k] == "O"
#print(c, lst, remove, top, k)
return ''.join(lst)


Last updated