From 439f5836dd5d4c157615150dbe5a6112c100b6bd Mon Sep 17 00:00:00 2001 From: wisdompeak Date: 2022年5月29日 18:11:06 -0700 Subject: [PATCH 1/2] Create 2289.Steps-to-Make-Array-Non-decreasing_v1.cpp --- ....Steps-to-Make-Array-Non-decreasing_v1.cpp | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 Design/2289.Steps-to-Make-Array-Non-decreasing/2289.Steps-to-Make-Array-Non-decreasing_v1.cpp diff --git a/Design/2289.Steps-to-Make-Array-Non-decreasing/2289.Steps-to-Make-Array-Non-decreasing_v1.cpp b/Design/2289.Steps-to-Make-Array-Non-decreasing/2289.Steps-to-Make-Array-Non-decreasing_v1.cpp new file mode 100644 index 000000000..c6fca16f9 --- /dev/null +++ b/Design/2289.Steps-to-Make-Array-Non-decreasing/2289.Steps-to-Make-Array-Non-decreasing_v1.cpp @@ -0,0 +1,47 @@ +class Solution { +public: + int totalSteps(vector& nums) + { + int n = nums.size(); + list List; + unordered_map::iterator>key2iter; + for (int i=0; iq; + for (int i=1; inums[i]) + q.push(i); + + int step = 0; + while (!q.empty()) + { + int len = q.size(); + unordered_setSet; + while (len--) + { + int i = q.front(); + q.pop(); + + auto iter = key2iter[i]; + if (Set.count(i)) + Set.erase(i); + if (next(iter)!=List.end()) + Set.insert(*next(iter)); + List.erase(iter); + } + + for (int i: Set) + { + if (key2iter[i]!=List.begin() && nums[*prev(key2iter[i])]> nums[i]) + q.push(i); + } + step++; + } + + return step; + } +}; From 7b224cbc6c9afe0c051e219e815762fd4fb22da0 Mon Sep 17 00:00:00 2001 From: wisdompeak Date: 2022年5月29日 18:12:14 -0700 Subject: [PATCH 2/2] Update Readme.md --- Readme.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Readme.md b/Readme.md index efb79a8fc..e578becc2 100644 --- a/Readme.md +++ b/Readme.md @@ -290,9 +290,6 @@ [2179.Count-Good-Triplets-in-an-Array](https://github.com/wisdompeak/LeetCode/tree/master/Segment_Tree/2179.Count-Good-Triplets-in-an-Array) (H) #### [Design](https://github.com/wisdompeak/LeetCode/tree/master/Design) -[146.LRU-Cache](https://github.com/wisdompeak/LeetCode/tree/master/Design/146.LRU-Cache) (H-) -[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) [380.Insert-Delete-GetRandom-O(1)](https://github.com/wisdompeak/LeetCode/tree/master/Design/380.Insert-Delete-GetRandom-O-1/) (M+) [381.Insert-Delete-GetRandom-O1-Duplicates-allowed](https://github.com/wisdompeak/LeetCode/tree/master/Design/381.Insert-Delete-GetRandom-O1-Duplicates-allowed) (H-) [716.Max-Stack](https://github.com/wisdompeak/LeetCode/tree/master/Design/716.Max-Stack) (M+) @@ -309,6 +306,11 @@ [1622.Fancy-Sequence](https://github.com/wisdompeak/LeetCode/tree/master/Design/1622.Fancy-Sequence) (H+) [1801.Number-of-Orders-in-the-Backlog](https://github.com/wisdompeak/LeetCode/tree/master/Design/1801.Number-of-Orders-in-the-Backlog) (M+) [2166.Design-Bitset](https://github.com/wisdompeak/LeetCode/tree/master/Design/2166.Design-Bitset) (M+) +* ``Linked List`` +[146.LRU-Cache](https://github.com/wisdompeak/LeetCode/tree/master/Design/146.LRU-Cache) (H-) +[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) #### [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)

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