Why this solution result in Output Limit Exceeded?


  • 0
    M
    void connect(TreeLinkNode *root) {
    if(root == NULL) return;
    queue<TreeLinkNode *> q;
    q.push(root);
    while(!q.empty()){
    	for(int i = q.size();i>0;i--){
    		TreeLinkNode *tmp = q.front();
    		q.pop();
    		if(q.size() > 0) tmp->next = q.front();
    		if(tmp->left) q.push(tmp->left);
    		if(tmp->right) q.push(tmp->right);
    	}
    }        
    

    }


Log in to reply
 

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