Answers for "recursive reverse l inedlist"

C#
1

Write a recursive function to reverse a list

l = [1,2,4,6]
def recursive(l):
    if len(l) == 0:
        return []  # base case
    else:
        return [l.pop()] + recursive(l)  # recusrive case


print recursive(l)

>[6,4,2,1]
Posted by: Guest on January-29-2021
1

recursive reverse linked list

public ListNode reverseList(ListNode head) {
    if (head == null || head.next == null) return head;
    ListNode p = reverseList(head.next);
    head.next.next = head;
    head.next = null;
    return p;
}
Posted by: Guest on August-22-2021

Code answers related to "recursive reverse l inedlist"

C# Answers by Framework

Browse Popular Code Answers by Language