Skip to content

Commit

Permalink
Update 2296.Design-a-Text-Editor_v1.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
wisdompeak authored Jun 11, 2022
1 parent 1a1b035 commit 50cf5fc
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions Design/2296.Design-a-Text-Editor/2296.Design-a-Text-Editor_v1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,13 @@ class TextEditor {
list<char>::iterator iter;
public:
TextEditor() {
t.push_back('#');
iter = t.begin();
}

void addText(string text)
{
for (auto ch: text)
{
t.insert(iter, ch);
}
}

int deleteText(int k)
Expand All @@ -24,7 +21,7 @@ class TextEditor {
t.erase(iter2);
k--;
ret++;
}
}
return ret;
}

Expand All @@ -35,36 +32,36 @@ class TextEditor {
iter = prev(iter);
k--;
}
int p = 10;
while (iter!=t.begin() && p>0)
int p = 0;
while (iter!=t.begin() && p<10)
{
iter = prev(iter);
p--;
p++;
}
string ret;
for (int i=0; i<10-p; i++)
for (int i=0; i<p; i++)
{
ret.push_back(*iter);
iter = next(iter);
}
return ret;
return ret;
}

string cursorRight(int k)
{
while (*iter!='#' && k>0)
while (iter!=t.end() && k>0)
{
iter = next(iter);
k--;
}
int p = 10;
while (iter!=t.begin() && p>0)
int p = 0;
while (iter!=t.begin() && p<10)
{
iter = prev(iter);
p--;
p++;
}
string ret;
for (int i=0; i<10-p; i++)
for (int i=0; i<p; i++)
{
ret.push_back(*iter);
iter = next(iter);
Expand Down

0 comments on commit 50cf5fc

Please sign in to comment.