import java.util.*;
/*
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){
return null;
}
ListNode proNode = null;
ListNode nextNode = head.next;
while(head!=null){
head.next = proNode;
proNode = head;
head = nextNode;
if(nextNode!=null){
nextNode = nextNode.next;
}
}
return proNode;
}
}
BM1反转链表(LeetCode)
于 2022-09-02 23:29:28 首次发布