题目考察的知识点:二叉树遍历

题目解答方法的文字分析:搜索二叉树采用前序遍历,然后逐个插入到v数组中

本题解析所用的编程语言:c++

/**
 * struct TreeNode {
 *	int val;
 *	struct TreeNode *left;
 *	struct TreeNode *right;
 *	TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 * };
 */
class Solution {
public:
    /**
     * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
     *
     * 
     * @param root TreeNode类 
     * @return int整型vector
     */
    void inorder(TreeNode* root, vector<int>& v)
    {
        if (root == nullptr)
            return;
        inorder(root->left, v);
        v.push_back(root->val);
        inorder(root->right, v);
    }
    vector<int> inorderTraversal(TreeNode* root) {
        // write code here
        vector<int> v;
        inorder(root, v);
        return v;
    }
};