From bb78a4570f31829421bc528d9cc61b8aff28cb05 Mon Sep 17 00:00:00 2001 From: wisdompeak Date: Wed, 8 Jun 2022 15:56:46 -0700 Subject: [PATCH 1/4] Update Readme.md --- Readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Readme.md b/Readme.md index 8ff41002a..6c5c036d4 100644 --- a/Readme.md +++ b/Readme.md @@ -189,7 +189,7 @@ [2071.Maximum-Number-of-Tasks-You-Can-Assign](https://github.com/wisdompeak/LeetCode/tree/master/Binary_Search/2071.Maximum-Number-of-Tasks-You-Can-Assign) (H) * ``Maintain intervals`` [715.Range-Module](https://github.com/wisdompeak/LeetCode/tree/master/Segment_Tree/715.Range-Module) (H) -[2213.Longest-Substring-of-One-Repeating-Character](https://github.com/wisdompeak/LeetCode/new/master/Heap/2213.Longest-Substring-of-One-Repeating-Character) (H) +[2213.Longest-Substring-of-One-Repeating-Character](https://github.com/wisdompeak/LeetCode/tree/master/Heap/2213.Longest-Substring-of-One-Repeating-Character) (H) [2276.Count-Integers-in-Intervals](https://github.com/wisdompeak/LeetCode/tree/master/Heap/2276.Count-Integers-in-Intervals) (H-) #### [Tree](https://github.com/wisdompeak/LeetCode/tree/master/Tree) From 44c7d5345b1c030f469164cbeb646210a8d61d31 Mon Sep 17 00:00:00 2001 From: wisdompeak Date: Thu, 9 Jun 2022 08:53:46 -0700 Subject: [PATCH 2/4] Create 2296.Design-a-Text-Editor_v1.cpp --- .../2296.Design-a-Text-Editor_v1.cpp | 83 +++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 Design/2296.Design-a-Text-Editor/2296.Design-a-Text-Editor_v1.cpp diff --git a/Design/2296.Design-a-Text-Editor/2296.Design-a-Text-Editor_v1.cpp b/Design/2296.Design-a-Text-Editor/2296.Design-a-Text-Editor_v1.cpp new file mode 100644 index 000000000..cf6ae12be --- /dev/null +++ b/Design/2296.Design-a-Text-Editor/2296.Design-a-Text-Editor_v1.cpp @@ -0,0 +1,83 @@ +class TextEditor { + listt; + list::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) + { + int ret = 0; + while (iter!=t.begin() && k>0) + { + auto iter2 = prev(iter); + t.erase(iter2); + k--; + ret++; + } + return ret; + } + + string cursorLeft(int k) + { + while (iter!=t.begin() && k>0) + { + iter = prev(iter); + k--; + } + int p = 10; + while (iter!=t.begin() && p>0) + { + iter = prev(iter); + p--; + } + string ret; + for (int i=0; i<10-p; i++) + { + ret.push_back(*iter); + iter = next(iter); + } + return ret; + } + + string cursorRight(int k) + { + while (*iter!='#' && k>0) + { + iter = next(iter); + k--; + } + int p = 10; + while (iter!=t.begin() && p>0) + { + iter = prev(iter); + p--; + } + string ret; + for (int i=0; i<10-p; i++) + { + ret.push_back(*iter); + iter = next(iter); + } + return ret; + } +}; + +/** + * Your TextEditor object will be instantiated and called as such: + * TextEditor* obj = new TextEditor(); + * obj->addText(text); + * int param_2 = obj->deleteText(k); + * string param_3 = obj->cursorLeft(k); + * string param_4 = obj->cursorRight(k); + */ From 8789f5ea4351e2e64576a8873ea994cb0bc7a008 Mon Sep 17 00:00:00 2001 From: wisdompeak Date: Thu, 9 Jun 2022 08:54:10 -0700 Subject: [PATCH 3/4] Create 2296.Design-a-Text-Editor_v2.cpp --- .../2296.Design-a-Text-Editor_v2.cpp | 76 +++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 Design/2296.Design-a-Text-Editor/2296.Design-a-Text-Editor_v2.cpp diff --git a/Design/2296.Design-a-Text-Editor/2296.Design-a-Text-Editor_v2.cpp b/Design/2296.Design-a-Text-Editor/2296.Design-a-Text-Editor_v2.cpp new file mode 100644 index 000000000..a9291983c --- /dev/null +++ b/Design/2296.Design-a-Text-Editor/2296.Design-a-Text-Editor_v2.cpp @@ -0,0 +1,76 @@ +class TextEditor { + stackst1; + stackst2; +public: + TextEditor() { + + } + + void addText(string text) + { + for (auto ch: text) + st1.push(ch); + } + + int deleteText(int k) + { + int ret = min(k, (int)st1.size()); + for (int i=0; iaddText(text); + * int param_2 = obj->deleteText(k); + * string param_3 = obj->cursorLeft(k); + * string param_4 = obj->cursorRight(k); + */ From cdd0d75cf3cabd4d6bdeff33f4602110ff1e4315 Mon Sep 17 00:00:00 2001 From: wisdompeak Date: Thu, 9 Jun 2022 08:54:47 -0700 Subject: [PATCH 4/4] Update Readme.md --- Readme.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Readme.md b/Readme.md index 6c5c036d4..8af49f275 100644 --- a/Readme.md +++ b/Readme.md @@ -309,6 +309,7 @@ [460.LFU Cache](https://github.com/wisdompeak/LeetCode/tree/master/Design/460.LFU-Cache) (H) [432.All-O-one-Data-Structure](https://github.com/wisdompeak/LeetCode/tree/master/Design/432.All-O-one-Data-Structure) (H) [2289.Steps-to-Make-Array-Non-decreasing](https://github.com/wisdompeak/LeetCode/tree/master/Design/2289.Steps-to-Make-Array-Non-decreasing) (H) +[2296.Design-a-Text-Editor](https://github.com/wisdompeak/LeetCode/tree/master/Design/2296.Design-a-Text-Editor) (M+) #### [Stack](https://github.com/wisdompeak/LeetCode/tree/master/Stack) [032.Longest-Valid-Parentheses](https://github.com/wisdompeak/LeetCode/tree/master/Stack/032.Longest-Valid-Parentheses) (H) @@ -326,6 +327,7 @@ [1209.Remove-All-Adjacent-Duplicates-in-String-II](https://github.com/wisdompeak/LeetCode/tree/master/Stack/1209.Remove-All-Adjacent-Duplicates-in-String-II) (M+) [1586.Binary-Search-Tree-Iterator-II](https://github.com/wisdompeak/LeetCode/tree/master/Stack/1586.Binary-Search-Tree-Iterator-II) (H) [2197.Replace-Non-Coprime-Numbers-in-Array](https://github.com/wisdompeak/LeetCode/tree/master/Stack/2197.Replace-Non-Coprime-Numbers-in-Array) (H-) +[2296.Design-a-Text-Editor](https://github.com/wisdompeak/LeetCode/tree/master/Design/2296.Design-a-Text-Editor) (M+) * ``monotonic stack`` [042.Trapping-Rain-Water](https://github.com/wisdompeak/LeetCode/tree/master/Others/042.Trapping-Rain-Water) (H) [084.Largest-Rectangle-in-Histogram](https://github.com/wisdompeak/LeetCode/tree/master/Stack/084.Largest-Rectangle-in-Histogram) (H)

AltStyle によって変換されたページ (->オリジナル) /