标签:leetcode
Reverse a singly linked list.
/**
* 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) {
ListNode pre = null;
ListNode next = null;
ListNode cur = head;
if(head!=null){
while(cur.next!=null){
next = cur.next;
cur.next = pre;
pre =cur;
cur = next;
}
cur.next =pre;
}
return cur;
}
}
标签:leetcode
原文地址:http://blog.csdn.net/tule_ant/article/details/45532323