It says 'didn't complete in the allocated time limit'. I have used only one while loop


#1

ListNode* Solution::solve(ListNode* A) {
ListNode *B;
ListNode *C;
ListNode *D;
ListNode *E;
ListNode *next;
B = NULL;
C = A;

while(C != NULL){
    if(C->val == 1) {
        next = C->next;
        C->next = B;
        B = C;
        C = next;
    }
    else{
        next = C->next;
        E = D;
        D = C;
        
        D -> next = B;
        E -> next = D;
        D = E;
        
    }
}