Untitled
unknown
python
a year ago
791 B
4
Indexable
class TextEditor: def __init__(self): self.text = "" self.cursor = 0 def addText(self, text: str) -> None: self.text = self.text[:self.cursor] + text + self.text[self.cursor:] self.cursor += len(text) def deleteText(self, k: int) -> int: delete_count = min(k, self.cursor) self.text = self.text[:self.cursor - delete_count] + self.text[self.cursor:] self.cursor -= delete_count return delete_count def cursorLeft(self, k: int) -> str: self.cursor = max(0, self.cursor - k) return self.text[max(0, self.cursor - 10):self.cursor] def cursorRight(self, k: int) -> str: self.cursor = min(len(self.text), self.cursor + k) return self.text[max(0, self.cursor - 10):self.cursor]
Editor is loading...
Leave a Comment