Skip to content

Commit 53edba1

Browse files
committed
update: reverse a linked list
1 parent e0da76d commit 53edba1

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

Diff for: LinkedList/ReverseALinkList.cpp

+11-5
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,20 @@ class Solution {
3030
// recursively reverse the rest of the list
3131
// and then connect the reversed list to the head
3232
// of the original list
33-
ListNode *previous = reverseList(head->next);
33+
ListNode *previous = reverseListR(head->next);
3434
// example:
35-
// head->next->next
36-
// ___⬇____
35+
// head->next->next = head
36+
// ____⬇___
3737
// ⬇ ⬆
3838
// [1] -> [2] -> [3] -> [4] -> [5]
39-
//
40-
// head
39+
//
40+
// head
41+
// head->next->next = head
42+
// ____⬇___
43+
// ⬇ ⬆
44+
// [1] -> [2] -> [3] -> [4] <- [5]
45+
//
46+
// head
4147
head->next->next = head;
4248
head->next = NULL;
4349
return previous;

0 commit comments

Comments
 (0)