Please help me with this problem, couldn't get the right answer. (c++)

  • 0

    Wrong Answer
    Input: {1,2}
    Output: [1,2,1]
    Expected: [2,1]

    vector<int> postorderTraversal(TreeNode *root) {
    static vector<int> results;
    if(!root)return results;
    return results;}

  • 0

    Please read the FAQ, specifically the question "Why does my code produce a different output compared to my local environment?"

  • 0

    You are using a static vector member, I guess the first test case was {1}, and you got it right, but as it is a static member, it will not be empty the second time it's called.

Log in to reply

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