p206 发表于 2016-07-27 | 分类于 blog | LeetCode 206 Reverse Linked List 题解1.题目: Reverse a singly linked list. 题意: 将一个链表反转 2.解题思路: 见代码 3.代码 [title] [] [url] [link text]123456789101112131415161718192021222324252627282930 public class Solution { public ListNode reverseList(ListNode head) { if (head==null) return head; if (head.next==null) { ListNode listNode = new ListNode(head.val); return listNode; } ListNode ans =reverseList(head.next); ListNode n =new ListNode(head.val); ListNode now=ans; for (;;)//注意循环到终点再定位next { if(now.next==null) { now.next=n; break; } now=now.next; } return ans; }} 4.一些总结: