/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
class Solution {
public:
vector<int>obj;
vector<int> preorderTraversal(TreeNode* root) {
if(root==NULL)
{
return obj;
}
obj.push_back(root->val);
if(root->left!=NULL)
{
preorderTraversal(root->left);
}
if(root->right!=NULL)
{
preorderTraversal(root->right);
}
return obj;
}
};
LeetCode:144.二叉树的前序遍历
猜你喜欢
转载自blog.csdn.net/dosdiosas_/article/details/105711319
今日推荐
周排行