TL;DR ( ~71.86 %) hard-to-read solution in C. How to optimize more?


  • 0
    V
    struct ListNode* addTwoNumbers(struct ListNode* l1, struct ListNode* l2)
    {
        struct ListNode* head,*pt,*node;
        int j = 0,temp = 0;
        int b;
        head = l1;
        
        while (l1)
        {
            node = l1;
            b = l1->val;
            
            // j + b
            temp = ((j ^ b ^ ((j&b)<<1)) ^ (((j ^ b)&((j&b)<<1))<<1)) ^ (((j ^ b ^ ((j&b)<<1)) & (((j ^ b)&((j&b)<<1))<<1)) << 1);
            l1 = l1->next;
            if (l2){
                b = l2->val;
                l2 = l2->next;
                // temp + b
                temp = ((temp ^ b ^ ((temp&b)<<1)) ^ (((temp ^ b)&((temp&b)<<1))<<1)) ^ (((temp ^ b ^ ((temp&b)<<1)) & (((temp ^ b)&((temp&b)<<1))<<1)) << 1) ^ (((temp ^ b ^ ((temp&b)<<1)) ^ (((temp ^ b)&((temp&b)<<1))<<1)) & (((temp ^ b ^ ((temp&b)<<1)) & (((temp ^ b)&((temp&b)<<1))<<1)) << 1)) << 1;
            }
            
            // j >= 10
            j = (temp&16) >> 4 | (((temp&8) >> 3) & (((temp&4) >> 2) | ((temp&2) >> 1)));
            
            // b = j ? 10 : 0
            b = ((j&1)<<2 | (j&1)) << 1;
    
            // temp-10
            node->val = ~((~temp ^ b ^ ((~temp&b)<<1)) ^ (((~temp ^ b)&((~temp&b)<<1))<<1));
            
            pt = node;
        }
        
        
        if (l2) {
            pt->next = l2;
        }
        while (l2)
        {
            node = l2;
            
            b = l2->val;
            
            l2 = l2->next;
            
            // j + b
            temp = ((j ^ b ^ ((j&b)<<1)) ^ (((j ^ b)&((j&b)<<1))<<1)) ^ (((j ^ b ^ ((j&b)<<1)) & (((j ^ b)&((j&b)<<1))<<1)) << 1);
            
            // j >= 10
            j = (temp&16) >> 4 | (((temp&8) >> 3) & (((temp&4) >> 2) | ((temp&2) >> 1)));
            
            // b = j ? 10 : 0
            b = ((j&1)<<2 | (j&1)) << 1;
    
            // temp-10
            node->val = ~((~temp ^ b ^ ((~temp&b)<<1)) ^ (((~temp ^ b)&((~temp&b)<<1))<<1));
            
            pt = node;
    
        }
        
        // j == 0 or j == 1
        if (j)
        {
            node = (struct ListNode*) malloc(sizeof(struct ListNode));
    
            node->val = 1;
            node->next = NULL;
            pt->next = node;
        }  
    
        return head;
    }
    

Log in to reply
 

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