链表数据结构
public class ListNode { public int val; public ListNode next; public ListNode(int x) { val = x; } }
反转代码
public ListNode reverse(ListNode head) { ListNode p; ListNode tmp = head.next; head.next = null; while(tmp != null) { p = tmp; tmp = tmp.next; p.next = head; head = p; } return head;
}