/** * struct TreeNode { * int val; * struct TreeNode *left; * struct TreeNode *right; * }; */ class Solution { public: /** * * @param root TreeNode类 * @return int整型vector */ vector<int> ans; vector<int> preorderTraversal(TreeNode* root) { // write code here if(!root) return ans; ans.emplace_back(root->val); preorderTraversal(root->left); preorderTraversal(root->right); return ans; } };