commit 560b090dd56cb491ae8e97de7f00093e9767dd2f parent 2d501e2544eeca0f90d63eb6cb1afd4dfeb28b84 Author: Dimitrije Dobrota <mail@dimitrijedobrota.com> Date: Mon, 22 May 2023 11:25:39 +0200 Random Problem Diffstat:
A | Problems/0092.cpp | | | 20 | ++++++++++++++++++++ |
M | README.md | | | 1 | + |
2 files changed, 21 insertions(+), 0 deletions(-)
diff --git a/Problems/0092.cpp b/Problems/0092.cpp @@ -0,0 +1,20 @@ +class Solution { +public: + ListNode *reverseBetween(ListNode *head, int left, int right) { + ListNode top; + top.next = head; + ListNode *prev = ⊤ + + for (int i = 1; i < left; i++) prev = prev->next; + + ListNode *crnt = prev->next; + for (int i = 0; i < right - left; i++) { + ListNode *tmp = prev->next; + prev->next = crnt->next; + crnt->next = crnt->next->next; + prev->next->next = tmp; + } + + return top.next; + } +}; diff --git a/README.md b/README.md @@ -106,6 +106,7 @@ for solving problems. | 0088 | Easy | [Merge Sorted Array](Problems/0088.cpp) | | 0090 | Medium | [Subsets II](Problems/0090.cpp) | | 0091 | Medium | [Decode Ways](Problems/0091.cpp) | +| 0092 | Medium | [Reverse Linked List II](Problems/0092.cpp) | | 0093 | Medium | [Restore IP Addresses](Problems/0093.cpp) | | 0094 | Easy | [Binary Tree Inorder Traversal](Problems/0094.cpp) | | 0096 | Medium | [Unique Binary Search Trees](Problems/0096.cpp) |