1# Runtime: 309 ms (Top 14.94%) | Memory: 18.7 MB (Top 36.81%)2class Solution:3def removeDuplicates(self, s: str, k: int) -> str:4stack = []5res = ""6for i in range(len(s)):7if len(stack) == 0:8stack.append([s[i], 1])9elif stack[-1][0] == s[i]:10stack[-1][1] = stack[-1][1] + 111else:12stack.append([s[i], 1])13if stack[-1][1] == k:14stack.pop()15for i in range(len(stack)):16res += stack[i][0] * stack[i][1]17return res