bugfree Icon
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course

Leetcode Problem 2296. Design a Text Editor

2296. Design a Text Editor

Leetcode Solutions

Using Two Stacks

  1. Initialize two stacks, left and right.
  2. For addText, push each character of the text onto the left stack.
  3. For deleteText, pop k characters from the left stack, or until the left stack is empty.
  4. For cursorLeft, pop k characters from the left stack and push them onto the right stack.
  5. For cursorRight, pop k characters from the right stack and push them onto the left stack.
  6. To return the last min(10, len) characters to the left of the cursor, pop up to 10 characters from the left stack, construct the string, and then push the characters back onto the left stack.
UML Thumbnail

Using Two Strings

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...