94. Binary Tree Inorder Traversal . Please tell me whats wrong in my code

i want to create vector v1 inside inorderTraversal function only and no othere separate function so how to do this and i have done this anyone please rectify it.

class Solution {
public:
    vector<int> inorderTraversal(TreeNode* root) {
        vector<int> v1;
        if(!root) return v1;
        inorderTraversal(root->left);
        v1.push_back(root->val);
        inorderTraversal(root->right);
        return v1;
    }
};
Comments (2)