0ms C++ Solution Using Recursion


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

Log in to reply
 

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