public static ListNode reverse(ListNode head){
if (head==null || head.next==null) return head;
ListNode last=null;
ListNode tmp;
while(head!=null){
tmp=head.next;
head.next=last;
last=head;
head=tmp;
}
return last;
}
反转链表
最新推荐文章于 2024-06-14 09:15:00 发布