Java-InPlace-Easy to understand


  • 2
    A
    public ListNode reverseList(ListNode head) {
            if(head==null||head.next==null) return head;
            ListNode prev, curr, next;
            prev = null;
            curr = head;
            next = null;
            
            while(curr!=null){
                next=curr.next;
                curr.next=prev;
                prev=curr;
                curr=next;
            }
            return prev;
        }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.