Answers for "reverse linked list recursive in c"

C#
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
5

recursively reverse linked list

public ListNode ReverseList(ListNode head) 
 {
   if(head==null || head.next == null)
   	return head;

  var t = ReverseList(head.next);
  head.next.next = head;
  head.next = null;

  return t;
}
Posted by: Guest on April-25-2022

C# Answers by Framework

Browse Popular Code Answers by Language