4ms C code, not perfect codes but clear codes


  • 2
    L
    struct ListNode* oddEvenList(struct ListNode* head) {
        
        if (head){
        
        struct ListNode* p = head;
        struct ListNode* q = head->next;
        struct ListNode* temp = q;
        
        while(p->next && q->next){
            p -> next = q->next;
            p = p->next;
            
            q -> next = p -> next;
            q = q->next;
        }
        p -> next = temp;
        }
        
        return head;
        
        
    }

Log in to reply
 

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