Design a Text Editor LeetCode solution in Java
1class TextEditor {2StringBuilder res;3int pos = 0;45public TextEditor() {6res = new StringBuilder();7}89public void addText(String text) {10res.insert(pos, text);11pos += text.length();12}1314public int deleteText(int k) {15int tmp = pos;16pos -= k;17if (pos < 0) pos = 0;18res.delete(pos, tmp);19return tmp - pos;20}2122public String cursorLeft(int k) {23pos -= k;24if (pos < 0) pos = 0;25if (pos < 10) return res.substring(0, pos);26return res.substring(pos - 10, pos);27}2829public String cursorRight(int k) {30pos += k;31if (pos > res.length()) pos = res.length();32if (pos < 10) return res.substring(0, pos);33return res.substring(pos - 10, pos);34}35}