import java.util.*;
public class ListNode {
int val;
ListNode next = null;
public ListNode(int val) {
this.val = val;
}
}
public class Test{
public ListNode ReverseList (ListNode head) {
if(head==null){
return null;
}
ListNode newhead=null;
ListNode temp=null;
while(head!=null){
temp=head.next;
head.next=newhead;
newhead=head;
head=temp;
}
return newhead;
}
}
链表--翻转
于 2024-08-01 18:44:51 首次发布