C++ Recursive 0ms. No member variables, No additional functions.


  • 0
    C
    class Solution {
        public:
            vector<int> inorderTraversal(TreeNode* root) {
                if(!root) {
                    vector<int> result;
                    return result;
                }
                vector<int> left = inorderTraversal(root->left);
                left.push_back(root->val);
                vector<int> right = inorderTraversal(root->right);
                
                left.insert(left.end(), right.begin(), right.end());
                return left;
            }
        };

  • 0
    K

    @cuichenxuan Nice one :)


Log in to reply
 

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