前序遍历二叉树
binary-tree-preorder-traversal
https://www.nowcoder.com/practice/501fb3ca49bb4474bf5fa87274e884b4?tpId=46&tqId=29036&tPage=1&rp=1&ru=%2Fta%2Fleetcode&qru=%2Fta%2Fleetcode%2Fquestion-ranking
利用递归简单的实现: class Solution { public: vector<int> preorderTraversal(TreeNode *root) { vector<int> res; helper(root, res); return res; } private: void helper(TreeNode * root ,vector<int>& res) { if(root == NULL)return ; res.push_back(root->val); helper(root->left , res); helper(root->right, res); } };