RunTime Error


  • -1
    G

    int widthOfBinaryTree(TreeNode* root) {
    deque<TreeNode*> q1,q2;
    q2.push_back(root);int max=0;int count=0;
    while(!q1.empty()||!q2.empty()){
    TreeNode *temp;
    if(!q1.empty()){
    temp=q1.front();
    while(temp==NULL){
    q1.pop_front();
    temp=q1.front();
    }
    }
    if(!q1.empty()){
    TreeNode *temp_back=q1.back();
    while(temp_back==NULL){
    q1.pop_back();
    temp_back=q1.back();
    }
    }
    while(!q1.empty()){
    count++;
    temp=q1.front();
    if(temp!=NULL){
    q2.push_back(temp->left);
    q2.push_back(temp->right);
    }
    q1.pop_front();
    }
    if(max<count)max=count;
    count=0;

        if(!q2.empty()){
              temp=q2.front();
              while(temp==NULL){
                  q2.pop_front();
                  temp=q2.front();
              }
        }
            if(!q2.empty()){
              TreeNode *temp_back=q2.back();
              while(temp_back==NULL){
                  q2.pop_back();
                  temp_back=q2.back();
              }
          }        
              while(!q2.empty()){
              count++;
                  TreeNode *t=q2.front();           
              if(t!=NULL){
                  //printf("%d ",temp->val);                 
                 q1.push_back(t->left);
                 q1.push_back(t->right);
              }
                  q2.pop_front();
              }
             if(max<count)max=count;
            count=0;                   
        }
        return max;      
    }
    

    Line 70: reference binding to misaligned address 0x00000001dc99 for type 'struct TreeNode *', which requires 8 byte alignment

    • list item

Log in to reply
 

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