Files
java/src/com/hong/www/Q12.java
T
2026-10-15 16:33:02 +08:00

22 lines
429 B
Java

package com.hong.www;
public class Q12 {
public ListNode dfs(ListNode root){
ListNode next;
ListNode temp=null;
while (root!=null) {
next=root.next;
root.next=temp;
root=next;
temp=root;
}
return temp;
}
public ListNode reverseList(ListNode head) {
ListNode dummy = new ListNode(0);
return dfs(head);
}
}