1.递归法
public ListNode reverseList(ListNode head) {
if(head==null||head.next==null) return head;
ListNode p = reverseList(head.next);
head.next.next=head;
head.next=null;
return p;
}
2.迭代法
public ListNode reverseList(ListNode head) {
ListNode prv=null;
ListNode cur=head;
ListNode temp ;
while(cur!=null){
temp=cur.next;
cur.next=prv;
prv=cur;
cur=temp;
}
return prv;
}

3496

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



