c++ 0ms simple solution with recursion


  • 0
    class Solution {
    public:
        vector<int> inorderTraversal(TreeNode* root) {
            vector<int> res;
            inorderTraversalCore(root, res);
            return res;
        }
        void inorderTraversalCore(TreeNode* root, vector<int>& res)
        {
            if(root==NULL)
                return;
            inorderTraversalCore(root->left, res);
            res.push_back(root->val);
            inorderTraversalCore(root->right, res);
        }
    };

  • 0
    G

    "Note: Recursive solution is trivial, could you do it iteratively?"


Log in to reply
 

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