LeetCode(144) Binary Tree Preorder Traversal
2015-07-26 19:40
363 查看
[code]/** * 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: void dfs(TreeNode *root, vector<int> &result) { if(NULL == root) return; result.push_back(root->val); dfs(root->left, result); dfs(root->right, result); } vector<int> preorderTraversal(TreeNode* root) { vector<int> result; dfs(root, result); return result; } };
相关文章推荐
- python实现ftp的基本功能
- CodeForces 534D Program B
- 以正能量的点!!!
- Swift学习笔记(八)——赋值运算符的返回值问题
- 二维数组行列转换
- Veriog_Notes_Summary 2
- if语句
- 南阳OJ独木舟上的旅行
- 重装WINDOWS系统后,恢复ORACLE 10G 全过程记录
- centos7.1 QT5编译出现:cannot find -lGL 和 collect2:error:ld returned 1 exit status 错误
- VREFpin的作用,为什么要做参考
- Android百分比布局的解析与扩展
- 函数重载
- Android 图形锁的实现
- Swift
- HDU-1548 A strange lift(单源最短路 或 BFS)
- Centos7.1安装CUDA7.0
- HDU 1030 ( Delta-wave )
- Readers/Writers lock
- 2015.7.26阅读笔记