题目描述:
反转一个单链表。
输入:
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 pre = null;
ListNode cur = head;
while(cur != null){
ListNode tmp = cur.next;
cur.next = pre;
pre = cur;
cur = tmp;
}
return pre;
}
}