Skip to content

Commit

Permalink
14.py
Browse files Browse the repository at this point in the history
  • Loading branch information
huisuu committed Aug 19, 2024
1 parent a512106 commit 5feccd5
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions HSKIM/11to20/14.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
def solution(n, k, cmd):
deleted = []
list = [i for i in range(0, n)]

for cmd_i in cmd:
if cmd_i == "C":
deleted.append(k)
list.remove(k)

elif cmd_i == "Z":
restore = deleted.pop()
list.insert(restore - 1, restore)

else:
action, num = cmd_i.split()
if action == "U":
k -= int(num)
elif action == "D":
k += int(num)

result = ["O"] * n
for i in range(len(deleted)):
result[deleted[i]] = "X"

return "".join(result)

# n = 8
# k = 2
# cmd = ['D 2', 'C', 'U 3', 'C', 'D 4', 'C', 'U 2', 'Z', 'Z', 'U 1', 'C']

# print(solution(n, k, cmd))

0 comments on commit 5feccd5

Please sign in to comment.