(Binary Tree Preorder Traversal )is the leetcode OJ wrong???

  • 0

    My solution:

    class Solution {
        vector<int> preorderTraversal(TreeNode *root) 
    		 static vector<int> vec;
    		 if (NULL == root) return vec;
    		 return vec;

  • 2

    this problem asks for Inorder Traversal, so OJ is not wrong.

  • 0

    I'm not at my best with c++, but from what I can tell, you have a working recursive preorder traversal. If you meant to put this question under that problem, I can't help you. On the other hand, if it were for this question, I don't think the response you are getting is "Wrong answer." That would assume it could compile, run, and return some value to the tester. As this is the Inorder Traversal problem, the tester calls vector<int> inorderTraversal(TreeNode* root) in the Solution class, which does not exist in your solution. I believe when you hit the submit button, it will return a compiler error, as tester is calling a nonexistent method.

Log in to reply

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