Message on Whatsapp 8879355057 for DSA(OA + Interview) + Fullstack Dev Training + 1-1 Personalized Mentoring to get 10+LPA Job
0 like 0 dislike
519 views

Hello all,

I'm trying to reverse a linked list in Java and am having some difficulty. I'm following the instructions in this post, but I'm getting an error when I run my code.

I'm including my code below. Any help would be greatly appreciated.

Thanks in advance!
public static ListNode reverseList(ListNode head) 


    ListNode prev = null; 
    ListNode curr = head; 
    ListNode next = null; 
    while (curr != null) { 
        next = curr.next; 
        curr.next = prev; 
        prev = curr; 
        curr = next; 
    } 
    head = prev; 
    return head; 
}

in Coding Resources by Expert (500 points) | 519 views

Please log in or register to answer this question.