题目地址:https://leetcode-cn.com/problems/binary-tree-preorder-traversal/
解题思路:树构造以及递归遍历
class Solution { vector<int> ans; public: vector<int> preorderTraversal(TreeNode* root) { if (root) { ans.push_back(root->val); preorderTraversal(root->left); preorderTraversal(root->right); } return ans; } };