Why my c++ solution "Run Time Error"


  • 0
    W
    class Solution {
    public:
        vector<int> postorderTraversal(TreeNode *root) {
            vector<int> help;
            stack<TreeNode *> result;
            stack<TreeNode *> s;
            
            if(root == NULL)    return help;
            
            s.push(root);
            while(!s.empty())
            {
                TreeNode *node=s.top();
                s.pop();
                result.push(node);
                
                if(node->left);
                    s.push(node->left);
                if(node->right)
                    s.push(node->right);
            }
            
            while(!result.empty())
            {
                help.push_back(result.top()->val);
                result.pop();
            }
            
            return help;
        }
    };

Log in to reply
 

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