I think it is right, who can tell me why it is wrong?


  • 0
    H

    public void reorderList(ListNode head)
    {
    if (head == null)
    {
    return;
    }
    LinkedList<Integer> list = new LinkedList<Integer>();
    ListNode current = head;
    while(current!=null)
    {
    list.add(current.val);
    current = current.next;
    }
    ListNode temp = head;
    while(!list.isEmpty())
    {
    temp = new ListNode(list.removeFirst());
    temp = temp.next;
    while(!list.isEmpty())
    {
    temp = new ListNode(list.removeLast());
    temp = temp.next;
    }
    }

    }

  • 0
    H

    please format your code correctly first.


Log in to reply
 

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