You are viewing a single comment's thread. Return to all comments →
class Stack: def __init__(self): self.stack = "" self.cache = [] def append(self, value): self.cache.append(self.stack) self.stack += value def pop_k(self, k_value): self.cache.append(self.stack) if len(self.stack) < k_value: self.stack = "" else: self.stack = self.stack[:-k_value] def print_c(self, kth_value): if len(self.stack) < kth_value: return "" return self.stack[kth_value-1] def undo(self): self.stack = self.cache[-1] self.cache.pop()
Seems like cookies are disabled on this browser, please enable them to open this website
Simple Text Editor
You are viewing a single comment's thread. Return to all comments →