# Use Recursion is simpler and quicker

• This problem could be solved by recursion, we first dig down to the middle node of the list, and recurse back from that point, the time complexity is O(N), and faster than existing algorithm.
1 -> 2 ->3 ->4, first dig down to 3, then recurse back, concatenate 2->3 (which already together), then 1->4(we return next node of each node starting from middle one)

``````public void reorderList(ListNode head){
}

public ListNode reorderList(ListNode prev, ListNode slow, ListNode faster){
if(faster == null || faster.next == null) {
if(faster != null) {
ListNode reverse = slow.next;
slow.next = null;
return reverse;
}
prev.next = null;
return slow;
}
ListNode retNode = reorderList(slow, slow.next, faster.next.next);
// concanate
ListNode temp = retNode.next;
retNode.next = slow.next;
slow.next = retNode;
return temp;
}``````

• In the case of 1->2->3->4, the last node 3 will point to itself.

• Faster than which existing algorithm? I don't think it is any faster than reversing the second half and merging the two halves from both ends. By the way, your algorithm takes O(N) extra stack space, whereas the reversing-merging algorithm needs only O(1).

• A recursive c++ implementation.

``````class Solution {
public:
{

if (!tail->next)
{
return true;
}

{
tail->next=NULL;
return false;
}

return true;
}

}
};``````

• After viewing your code, I still prefer the iterative algorithm.

• recursion takes O(n) space

• Your code failed the last test

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.