why java code run faster than c.


  • 0
    X

    I don't know why java code run faster than c code , here is my submit result.

    0_1478661860903_WechatIMG74.jpeg

    can anyone explain that?

    #define DEBUG 1
    
    struct ListNode* deleteDuplicates(struct ListNode* head) {
        struct ListNode * tmp = head, *pre = NULL;
        while(tmp){
            if(tmp->next){
                if(tmp->val != tmp->next->val){
                    if(pre == NULL) {
                        head = tmp;
                    }
                    pre = tmp;
                    if(DEBUG) {
                        printf("pre updated with :%d \n",tmp->val);
                    }
                }else {
                    while(tmp->next && tmp->val == tmp->next->val){
                        if (DEBUG) {
                            printf("remove element  %d \n",tmp->next->val);
                        }
                        tmp->next = tmp->next->next;
                    }
                    if( pre ){
                        pre->next = tmp->next;
                        if (DEBUG) {
                            printf("delete element  %d \n",tmp->val);
                        }
                    } else {
                        if (DEBUG) {
                            printf("delete element  %d \n",tmp->val);
                        }
                        head = pre;
                    }
                }
                tmp = tmp->next;
            } else {
                if(pre == NULL) {
                    head =  tmp;
                }
                break;
            }
        }
        return head;
    }
    

Log in to reply
 

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