leetcode#24交换节点对中运行时错误(C语言)

时间:2016-05-11 07:58:50

标签: c runtime-error

我尝试在this link上回答问题 但是,我发现我的答案在少量输入上工作得很好,但是leetcode网站在输入上给出了运行时错误

  

[4,77,57,79,24,47,21,42,38,54,26,28,30,85,32,40,62,28,89,37,24,3,51, 72,59,49,7,60,44,7,27,48,37,37,27,13,36,49,55,26,55,33,55,85,19,39,25,33, 68,14,70,44,70,73,68,29,22,27,89,66,35,69,67,24,58,94,37,46]

这是我的代码,有人能告诉我发生了什么吗?

    /**
     * Definition for singly-linked list.
     * struct ListNode {
     *     int val;
     *     struct ListNode *next;
     * };
     */
    struct ListNode* swapPairs(struct ListNode* head)
    {
        struct ListNode *dummy, *pi, *pj, *end;
        dummy->next = head;
        end = dummy;
        while(true){
            pi = end->next;    
            if(pi == NULL){
                break;
            }else{ 
                pj = pi->next;
            }
            if(pj == NULL){
                break;
            }
            end->next = pi->next;
            pi->next = pj->next;
            pj->next = pi;
            end = pi;
        }
        return dummy->next;
    }

1 个答案:

答案 0 :(得分:2)

@Component({
  selector: 'parent-cmp',
  template: `
    <wrapper-component *ngFor="let item of someJson" [type]="item.componentName"></wrapper-component>
  `})
export class ParentComponent {
  someJson; // assign the JSON here
}

你没有初始化struct ListNode *dummy, *pi, *pj, *end; dummy->next = head; ptr,但你使用它。