力扣2296.设计一个文本编辑器
class TextEditor {
string left,right;
public:
TextEditor() {
}
void addText(string text) {
left += text;
}
int deleteText(int k) {
k = min(k,(int)left.size());
left.resize(left.size() - k);
return k;
}
string text()
{
return left.substr(max((int)left.size() - 10,0));
}
string cursorLeft(int k) {
for(;k && !left.empty();k--)
{
right += left.back();
left.pop_back();
}
return text();
}
string cursorRight(int k)
{
for (; k && !right.empty(); --k)
{
left += right.back();
right.pop_back();
}
return text();
}
};