
1.栈遍历法代码public class Solution { public ListNode ReverseList(ListNode head) { if (head null || head.next null) return head; StackListNode nodes new StackListNode(); ListNode node head; while(node ! null) { var temp node.next; node.next nodes.TryPeek(out var top) ? top : null; nodes.Push(node); node temp; } return nodes.Pop(); } }结果2.双指针法代码public class Solution { public ListNode ReverseList(ListNode head) { ListNode previous null; ListNode current head; while (current ! null) { ListNode next current.next; current.next previous; previous current; current next; } return previous; } }结果3.递归法代码public class Solution { public ListNode ReverseList(ListNode head) Reverse(head, null); ListNode Reverse(ListNode current, ListNode previous) { if (current null) return previous; var temp current.next; current.next previous; return Reverse(temp, current); } }结果