二叉树的中序遍历
来源:互联网 发布:淘宝无线视频怎么添加 编辑:程序博客网 时间:2024/06/15 15:37
给出一棵二叉树,返回其中序遍历
样例
给出二叉树 {1,#,2,3}
,
1 \ 2 / 3
返回 [1,3,2]
解题思路:dfs遍历中序储存。
class Solution { /** * @param root: The root of binary tree. * @return: Inorder in vector which contains node values. */ vector<int>ans;public: vector<int> inorderTraversal(TreeNode *root) { // write your code here if(root==NULL)return ans; inorderTraversal(root->left); ans.push_back(root->val); inorderTraversal(root->right); return ans; }};
0 0
- 二叉树的中序遍历
- 二叉树的中序遍历
- 线索二叉树的中序遍历
- 有关二叉树的中序遍历
- 二叉树的中序遍历
- 排序二叉树的中序遍历
- 二叉树的中序遍历算法
- 题目:二叉树的中序遍历
- 二叉树的中序遍历
- 二叉树的中序遍历
- 二叉树的中序遍历
- LintCode -- 二叉树的中序遍历
- lintcode 二叉树的中序遍历
- 二叉树的前后中序遍历
- 二叉树的中序遍历
- 二叉树的中序遍历
- lintcode:二叉树的中序遍历
- lintcode,二叉树的中序遍历
- CentOS 7 配置Ruby语言开发环境
- Centos 文件和目录访问权限设置
- LinearLayoutCompat组件
- Spring boot干货系列:(一)优雅的入门篇
- Linux系统结构
- 二叉树的中序遍历
- Oracle/Scheduler和Job的基本概念
- 启动npm报错
- Ajax readyState一直为1或无法请求到后台的问题处理
- Python logging日志(1)
- q操作符Oracle's quote operator
- Spring Boot干货系列:(二)配置文件解析
- java基础-(杂乱知识点)
- Linux 搭建yum源