二叉树的前序遍历-LintCode
来源:互联网 发布:linux jmx监控tomcat 编辑:程序博客网 时间:2024/05/21 14:09
描述:
给出一棵二叉树,返回其节点值的前序遍历。
样例:
给出一棵二叉树 {1,#,2,3}
,
1 \ 2 / 3
返回 [1,2,3]
.
思路:
递归函数。
AC代码:/** * Definition of TreeNode: * class TreeNode { * public: * int val; * TreeNode *left, *right; * TreeNode(int val) { * this->val = val; * this->left = this->right = NULL; * } * } */class Solution {public: /** * @param root: The root of binary tree. * @return: Preorder in vector which contains node values. */ vector<int> v; void front(TreeNode *root) { if(root==NULL) return; else { v.push_back(root->val); front(root->left); front(root->right); } } vector<int> preorderTraversal(TreeNode *root) { // write your code here front(root); return v; }};
0 0
- LintCode -- 二叉树的前序遍历
- lintcode 二叉树的前序遍历
- lintcode,二叉树的前序遍历
- LintCode-二叉树的前序遍历
- lintcode 二叉树的前序遍历
- LintCode 二叉树的前序遍历
- lintcode二叉树的前序遍历
- 二叉树的前序遍历-LintCode
- Lintcode 二叉树的前序遍历
- lintcode--二叉树的前序遍历
- lintcode:二叉树的前序遍历
- lintcode-二叉树的前序遍历(非递归)-66
- LintCode之二叉树的前序遍历
- Lintcode 66 二叉树的前序遍历
- LintCode | 66. 二叉树的前序遍历
- lintcode——二叉树的前序遍历
- lintcode 66 二叉树的前序遍历
- LintCode 66 二叉树的前序遍历
- 下拉ul选择的写法
- 在线小说网站的设计与实现(附源码)
- 设计模式(一)
- 从新开始学习scala,有许多问题打扰各位大神了
- drools用户指南----stateful session(有状态会话)的使用
- 二叉树的前序遍历-LintCode
- XAMPP和WORDPRESS(上)
- hellocharts-android-Android图表开源库的使用(一)
- C#串口通信-向串口发送数据,同步接收返回数据
- POJ 2411 Mondriaan's Dream (状压dp)
- Terracatta安装windows&linux
- Android SD卡检测和SP数据保存不及时解决方案
- dubbo(一):dubbo简介
- python_Python中用format函数格式化字符串的用法