首页 > 学院 > 开发设计 > 正文

144. Binary Tree Preorder Traversal

2019-11-08 03:20:43
字体:
来源:转载
供稿:网友

PReorder,没啥好说的

/** * 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>ve; void preo(TreeNode* root){ if(root == NULL) return ; ve.push_back(root -> val); preo(root -> left); preo(root -> right); } vector<int> preorderTraversal(TreeNode* root) { preo(root); return ve; }};
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表