Skip to content

Commit 60aece3

Browse files
committed
Runtime: 380 ms (Top 41.73%) | Memory: 138.9 MB (Top 59.95%)
1 parent 0adddf1 commit 60aece3

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,36 @@
1+
// Runtime: 380 ms (Top 41.73%) | Memory: 138.9 MB (Top 59.95%)
12
class TextEditor {
23
StringBuilder res;
34
int pos=0;
4-
5+
56
public TextEditor() {
67
res = new StringBuilder();
78
}
8-
9+
910
public void addText(String text) {
1011
res.insert(pos,text);
1112
pos += text.length();
1213
}
13-
14+
1415
public int deleteText(int k) {
1516
int tmp = pos;
1617
pos -= k;
1718
if(pos<0) pos=0;
1819
res.delete(pos,tmp);
1920
return tmp-pos;
2021
}
21-
22+
2223
public String cursorLeft(int k) {
2324
pos-=k;
2425
if(pos<0) pos = 0;
2526
if(pos<10) return res.substring(0,pos);
2627
return res.substring(pos-10,pos);
2728
}
28-
29+
2930
public String cursorRight(int k) {
3031
pos+=k;
3132
if(pos>res.length()) pos = res.length();
3233
if(pos<10) return res.substring(0,pos);
3334
return res.substring(pos-10,pos);
3435
}
3536
}
36-

0 commit comments

Comments
 (0)