题目链接:
https://leetcode.com/problems/binary-tree-preorder-traversal/description/
class Solution {
public:
vector<int> preorderTraversal(TreeNode* root) {
vector<int> res ;
helper(root,res);
return res;
}
//1. get the left leaf of the nodes
public: void helper(TreeNode* root,vector<int>& resultVector){
if(root == NULL) //3. return condition
return ;
// 2.add the value and continue to find the left most
resultVector.push_back(root->val);
helper(root->left,resultVector);
helper(root->right,resultVector);
}
};