By 张旭 CaesarChang
关注我 带你看更多好的技术知识和面试题
输入: 1->2->3->4->5->NULL
输出: 5->4->3->2->1->NULL
/**
* 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 curNode=head;
ListNode preNode=null;
ListNode tempNode=null;
while(curNode!=null){
tempNode=curNode;
curNode=curNode.next;
tempNode.next=preNode;
preNode=tempNode;
}
return tempNode;
}
非常简单: