您的位置:首页 > 其它

206. Reverse Linked List

2016-03-01 14:51 113 查看
/**
* Definition for singly-linked list.
* public class ListNode {
*     int val;
*     ListNode next;
*     ListNode(int x) { val = x; }
* }
*/
public class Solution {
public ListNode reverseList(ListNode head) {
if(head==null) return head;
ListNode result = null ;
ListNode temp = null;
while (head!=null) {
if (head.next!=null)
{temp = head.next;
head.next = result;
result = head;
head = temp;}
else {
head.next = result;
result = head;
head = null;
}
}
return result;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: