LeetCode/com/zerroi/leetcode/Three23/ReverseList.java

23 lines
451 B
Java
Raw Permalink Normal View History

2024-03-25 20:14:01 +08:00
package com.zerroi.leetcode.Three23;
public class ReverseList {
public static void main(String[] args) {
}
}
class SolutionThird {
public ListNode reverseList(ListNode head) {
ListNode pre = null;
ListNode cur = head;
ListNode temp = null;
while (cur != null) {
temp = cur.next;
cur.next = pre;
pre = cur;
cur = temp;
}
return pre;
}
}