My code only has 39 lines, but i got a compile error: Line 53: expected '}' at end of input. Can anyone help me?


  • 0
    C
     vector<int> postorderTraversal(TreeNode *root) {
        vector<int> answer;
        if(root == NULL)
            return answer;
        stack<TreeNode*> nodes;
        TreeNode* cur = root;
        TreeNode* pre = NULL;
        nodes.push(root);
        while(!nodes.empty()){
            cur = nodes.top();
            if((cur->left == NULL && cur->right == NULL) || 
                       ((pre != NULL && (pre == cur->left || pre == cur->right))){
                answer.push_back(cur->val);
                nodes.pop();
                pre = cur;
            }
            else{
                if(cur->right != NULL)
                    nodes.push(cur->right);
                if
                    nodes.push(cur->left);
            }
        }
        
        return answer;
    }

  • 1
    M
            if((cur->left == NULL && cur->right == NULL) || 
                   ((pre != NULL && (pre == cur->left || pre == cur->right))){
            answer.push_back(cur->val);
            nodes.pop();
            pre = cur;
            }
    

    Needs one more closing parenthesis in the if statement. The initial parenthesis is not closed.


  • 0
    C

    @mbh621 Thanks a lot, i fixed my problems


Log in to reply
 

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