I don`t know why it is TLE?(Maybe OJ bug?)


  • 0
    C

    First of all, I misunderstood the question. So I regard node whose value is odd as odd Node.

    And I don`t know why it TLE when I input [1,2,3]?

    class Solution {
    public:
    ListNode* oddEvenList(ListNode* head) {
    ListNode* evenhead = new ListNode(-99);
    ListNode* fakehead = new ListNode(-98);
    fakehead->next = head;
    ListNode* p =fakehead;
    ListNode* evenheadp =evenhead;

        while(p->next!=NULL){
            if(p->next->val%2==1){
                p=p->next;
            }else{
                evenheadp->next = p->next;
                p->next = p->next->next;
                evenheadp = evenheadp->next;
            }
        }
        p->next = evenhead->next;
        return fakehead->next;
    }
    

    };


Log in to reply
 

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