【剑指Offer】反转链表 Posted on 2017-05-13 | In Algorithm , 剑指Offer 题目定义一个函数,输入一个链表的头结点,反转该链表并输出反转后链表的头结点。 实现12345678public class ListNode { int val; ListNode next = null; ListNode(int val) { this.val = val; }} 123456789101112131415161718public ListNode ReverseList(ListNode head) { ListNode current = head; ListNode previous = null; ListNode tail = null; while (current != null){ ListNode next = current.next; if (next == null) tail = current; current.next = previous; previous = current; current = next; } return tail;}