[leetcode]206. Reverse Linked List反转链表
/* 迭代方法,用一个pre指针保存当前已经反转的前半部分链表,每次循环用下一个节点指向pre 并且更新pre */ public ListNode reverseList(ListNode head) { ListNode pre = null; while (head!=null) { //下边要改变head,所以先保存下来next ListNode next = head.next; //将当前节点指向pre head.next = pre; //更新pre pre = head; //更新head往下遍历 head = next; } return pre; }
反转数字请看:http://www.cnblogs.com/stAr-1/p/8423922.html