From 2850bae3d6753246305eed7aa5bec9fdc8263c22 Mon Sep 17 00:00:00 2001 From: Pratik Shende Date: Thu, 13 Apr 2023 16:35:48 +0530 Subject: [PATCH 1/2] Create 0092-reverse-linked-list-ll.java --- java/0092-reverse-linked-list-ll.java | 61 +++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 java/0092-reverse-linked-list-ll.java diff --git a/java/0092-reverse-linked-list-ll.java b/java/0092-reverse-linked-list-ll.java new file mode 100644 index 000000000..816f87321 --- /dev/null +++ b/java/0092-reverse-linked-list-ll.java @@ -0,0 +1,61 @@ +/** + * Definition for singly-linked list. + * public class ListNode { + * int val; + * ListNode next; + * ListNode() {} + * ListNode(int val) { this.val = val; } + * ListNode(int val, ListNode next) { this.val = val; this.next = next; } + * } + */ +class Solution { + public ListNode reverseBetween(ListNode head, int left, int right) { + + if (head == null || head.next == null) { + return head; + } + + if (left > right || left == right) { + return head; + } + + ListNode l = head; + ListNode prevL = null; + ListNode r = head; + ListNode nextR = null; + int posL = 1; + int posR = 1; + + while (posL != left) { + prevL = l; + l = l.next; + posL++; + } + + while (posR != right) { + r = r.next; + posR++; + } + + nextR = r.next; + r.next = null; + ListNode node = reverseList(l); + node.next = nextR; + if (prevL == null) { + head = r; + } else { + prevL.next = r; + } + return head; + } + + public ListNode reverseList(ListNode l) { + if (l.next == null) { + return l; + } + ListNode newNode = reverseList(l.next); + newNode.next = l; + l.next = null; + return l; + } +} From 9e576b39e79fde9af0d31ac20330ed578418d358 Mon Sep 17 00:00:00 2001 From: Bot-A0 <71089234+Ahmad-A0@users.noreply.github.com> Date: Thu, 13 Apr 2023 12:09:49 +0000 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=93=9C=20Update=20README=20table=20(?= =?UTF-8?q?=F0=9F=9B=A0=EF=B8=8F=20from=20Github=20Actions)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 60021bad5..3acaa6167 100644 --- a/README.md +++ b/README.md @@ -183,7 +183,7 @@ If you would like to have collaborator permissions on the repo to merge your own [0148 - Sort List](https://leetcode.com/problems/sort-list/) |
[✔️](c%2F0148-sort-list.c)
|
|
|
|
|
[✔️](java%2F0148-sort-list.java)
|
|
|
[✔️](python%2F0148-sort-list.py)
|
|
|
|
|
[0086 - Partition List](https://leetcode.com/problems/partition-list/) |
|
|
|
|
|
[✔️](java%2F0086-partition-list.java)
|
|
|
[✔️](python%2F0086-partition-list.py)
|
|
|
|
|
[0061 - Rotate List](https://leetcode.com/problems/rotate-list/) |
|
[✔️](cpp%2F0061-rotate-list.cpp)
|
|
|
|
[✔️](java%2F0061-rotate-list.java)
|
|
|
[✔️](python%2F0061-rotate-list.py)
|
|
|
|
|
-[0092 - Reverse Linked List II](https://leetcode.com/problems/reverse-linked-list-ii/) |
|
[✔️](cpp%2F0092-reverse-linked-list-ii.cpp)
|
|
|
|
|
[✔️](javascript%2F0092-reverse-linked-list-ii.js)
|
|
[✔️](python%2F0092-reverse-linked-list-ii.py)
|
|
|
|
|
+[0092 - Reverse Linked List II](https://leetcode.com/problems/reverse-linked-list-ii/) |
|
[✔️](cpp%2F0092-reverse-linked-list-ii.cpp)
|
|
|
|
[✔️](java%2F0092-reverse-linked-list-ll.java)
|
[✔️](javascript%2F0092-reverse-linked-list-ii.js)
|
|
[✔️](python%2F0092-reverse-linked-list-ii.py)
|
|
|
|
|
[0622 - Design Circular Queue](https://leetcode.com/problems/design-circular-queue/) |
|
|
|
|
[✔️](go%2F0622-design-circular-queue.go)
|
|
|
[✔️](kotlin%2F0622-design-circular-queue.kt)
|
[✔️](python%2F0622-design-circular-queue.py)
|
|
|
|
|
[0147 - Insertion Sort List](https://leetcode.com/problems/insertion-sort-list/) |
|
|
|
|
|
|
|
|
[✔️](python%2F0147-insertion-sort-list.py)
|
|
|
|
|
[0146 - LRU Cache](https://leetcode.com/problems/lru-cache/) |
[✔️](c%2F0146-lru-cache.c)
|
[✔️](cpp%2F0146-lru-cache.cpp)
|
[✔️](csharp%2F0146-lru-cache.cs)
|
|
[✔️](go%2F0146-lru-cache.go)
|
[✔️](java%2F0146-lru-cache.java)
|
[✔️](javascript%2F0146-lru-cache.js)
|
[✔️](kotlin%2F0146-lru-cache.kt)
|
[✔️](python%2F0146-lru-cache.py)
|
[✔️](ruby%2F0146-lru-cache.rb)
|
|
|
|