Why there always has the wrong answer, any one could give me some suggestions?


  • 0
    V

    The following is my code, and it is block for the wrong answer.
    vector<int> preorderTraversal(TreeNode *root) {
    static vector<int> preorderTree ;
    if(root != NULL)
    {
    preorderTree.push_back(root->val);
    preorderTraversal(root->left);
    preorderTraversal(root->right);
    }
    return preorderTree;
    }


  • 0
    C

    check if root->left and root->right is valid before you use them.


Log in to reply
 

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