二叉树的中序遍历
来源:互联网 发布:易石软件怎样用 编辑:程序博客网 时间:2024/06/06 10:46
给出一棵二叉树,返回其中序遍历
样例
给出二叉树 {1,#,2,3}
,
1 \ 2 / 3
返回 [1,3,2]
.
/** * 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: A Tree * @return: Inorder in ArrayList which contains node values. */ vector<int> inorderTraversal(TreeNode * root) { // write your code here vector<int> temp; if(root == NULL) return temp; inorder(root,temp); return temp; } void inorder(TreeNode *root,vector<int> &path) { if(root != NULL) { inorder(root->left,path); path.push_back(root->val); inorder(root->right,path); } if(root == NULL) return ; }};
阅读全文
0 0
- 二叉树的中序遍历
- 二叉树的中序遍历
- 线索二叉树的中序遍历
- 有关二叉树的中序遍历
- 二叉树的中序遍历
- 排序二叉树的中序遍历
- 二叉树的中序遍历算法
- 题目:二叉树的中序遍历
- 二叉树的中序遍历
- 二叉树的中序遍历
- 二叉树的中序遍历
- LintCode -- 二叉树的中序遍历
- lintcode 二叉树的中序遍历
- 二叉树的前后中序遍历
- 二叉树的中序遍历
- 二叉树的中序遍历
- lintcode:二叉树的中序遍历
- lintcode,二叉树的中序遍历
- require.js源码分析之加载流程
- Spring mvc 注解总结 (上)
- Scala对MongoDB的增删改查操作
- Ubuntu16.04安装mongodb
- 过滤器和拦截器的区别简单几点
- 二叉树的中序遍历
- 在centos7下编译安装php7
- [LeetCode]2. Add Two Numbers
- linex 查看jpyter地址
- Java子类调用父类构造方法
- 机器学习-归一化、标准化
- 每日掌握一个Linux命令 之 bash shell 的内置命令 type
- 易飞安装在VMware虚拟机方法
- 论文发表费用