Java 代码
/**
* Definition for singly-linked list.
* public class ListNode {
* int val;
* ListNode next;
* ListNode(int x) { val = x; }
* }
*/
class Solution {
public ListNode reverseList(ListNode head)
{
ListNode node = head;
ListNode revNode = null;
while (node != null)
{
ListNode nextNode = revNode;
revNode = new ListNode(node.val);
revNode.next = nextNode;
node = node.next;
}
return revNode;
}
}