【算法】单链表反转(LeetCode-206)_if (head.next == null) return head; listnode last -CSDN博客

网站介绍:文章浏览阅读197次。不多说废话,题目是这样子的题目:反转一个单链表。示例:输入: 1->2->3->4->5->NULL输出: 5->4->3->2->1->NULL进阶:你可以迭代或递归地反转链表。你能否用两种方法解决这道题?解决思路单链表反转,大家说有很多种办法,其实无非就是头插法的各种实现!1、通过循环2、通过递归解法方法一:循环头插法1、创建一个虚拟节点和创建一个临时指针temp2、将tem.._if (head.next == null) return head; listnode last = reverse(head.next); head