Simple C++ solution


  • 1
    X

    class OddEvenLink{
    public:
    LinkNode* oddEvenList(ListNode* head)
    {
    if(!head)
    return head;
    ListNode* first = head
    ListNode* second = head->next;
    ListNode* temp = second;
    while(second && second->next)
    {
    first->next = second->next;
    first = first->next;
    second->next = first->next;
    second = second->next;
    }
    first->next = temp;
    return head;
    }
    }


Log in to reply
 

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