0ms Java iterator solution


  • 1
    Y
    public ListNode reverseList(ListNode head) {
        if(head==null) return head;
        ListNode temp1= head.next;
        ListNode temp2= null;
        head.next=null;
        while(temp1!=null){
            temp2=temp1.next;
            temp1.next=head;
            head=temp1;
            temp1=temp2;
        }
        return head;
    }

Log in to reply
 

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