LeetCode144
题目:
解法:
class Solution {
public:
void Findfirst(TreeNode* root,vector<int> & s)
{
if(root == NULL)
return;
else
s.push_back(root->val);
Findfirst(root->left,s);
Findfirst(root->right,s);
}
vector<int> preorderTraversal(TreeNode* root) {
vector<int> first;
Findfirst(root,first);
return first;
}
};
LeetCode145
题目:
class Solution {
public:
void Findfirst(TreeNode* root,vector<int> & s)
{
if(root == NULL)
return;
Findfirst(root->left,s);
Findfirst(root->right,s);
s.push_back(root->val);
}
vector<int> postorderTraversal(TreeNode* root) {
vector<int> first;
Findfirst(root,first);
return first;
}
};
LeetCode94
题目:
解法:
class Solution {
public:
void Findfirst(TreeNode* root,vector<int> & s)
{
if(root == NULL)
return;
Findfirst(root->left,s);
s.push_back(root->val);
Findfirst(root->right,s);
}
vector<int> inorderTraversal(TreeNode* root) {
vector<int> first;
Findfirst(root,first);
return first;
}
};