my simlple c++ solution


  • 0
    H
    class Solution {
    public:
        ListNode* oddEvenList(ListNode* head) {
            if(!head || !head->next)
                return head;
            ListNode *odd_head = head, *even_head = head->next;
            ListNode *odd_tail = odd_head, *even_tail = even_head;
            while(even_tail && even_tail->next){
                odd_tail = odd_tail->next = even_tail->next;
                even_tail = even_tail->next = odd_tail->next;
            }
            odd_tail->next = even_head;
            return odd_head;
        }
    };
    

Log in to reply
 

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