Digital Marketing

reverse-list-recursive.java

public ListNode reverseList(ListNode head) {
/* recursive solution */
return reverseListInt(head, null);
}

private ListNode reverseListInt(ListNode head, ListNode newHead) {
if (head == null)
return newHead;
ListNode next = head.next;
head.next = newHead;
return reverseListInt(next, head);
}

Comments

Popular posts from this blog

Fixed WSL sshd: no hostkeys available -- exiting

PowerMTA pmta command

How to fix: mv: failed to preserve ownership