/*
public class ListNode {
int val;
ListNode next = null;
ListNode(int val) {
this.val = val;
}
}*/
public class Solution {
public ListNode ReverseList(ListNode head) {
if (head ==null||head.next==null){
return head;
}
ListNode last = null;
while(head!=null){
ListNode temp = head.next;
head.next = last;
last = head;
head = temp;
}
return last;
}
}
Java实现反转链表
最新推荐文章于 2023-04-08 19:56:12 发布