题目描述
输入一个链表,反转链表后,输出新链表的表头。
源代码:
/*
public class ListNode {
int val;
ListNode next = null;
ListNode(int val) {
this.val = val;
}
}*/
public class Solution {
//post指向头结点的下一个节点,然后把头结点所指结点的next域指向前一个结点。
public ListNode ReverseList(ListNode head) {
ListNode pre=null;
ListNode post=null;
if(head == null) return null;
while(head!=null){
post=head.next;
head.next=pre;
pre=head;
head=post;
//head=head.next;
}
return pre;
}
}
3487



被折叠的 条评论
为什么被折叠?



