8000
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 02d8759 commit b9cc6bdCopy full SHA for b9cc6bd
Linked-List/92/solution2.js
@@ -0,0 +1,25 @@
1
+/**
2
+ * 时间复杂度:O(n)
3
+ * 空间复杂度:O(1)
4
+ */
5
+const reverseBetween = (head, m, n) => {
6
+ const dummyHead = new ListNode(null);
7
+ dummyHead.next = head;
8
+
9
+ let preHead = dummyHead;
10
+ for (let i = 0; i < m - 1; i++) {
11
+ preHead = preHead.next;
12
+ }
13
14
+ let current = preHead.next;
15
+ let next = null;
16
17
+ for (let i = 0; i < n - m; i++) {
18
+ next = current.next;
19
+ current.next = next.next;
20
+ next.next = preHead.next;
21
+ preHead.next = next;
22
23
24
+ return dummyHead.next;
25
+}
0 commit comments