[LintCode]67.二叉树的中序遍历
来源:互联网 发布:js烟花效果带文字 编辑:程序博客网 时间:2024/06/05 05:20
给出一棵二叉树,返回其中序遍历
样例
给出二叉树 {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) { vector<int> tmp; if(root==NULL) return tmp; stack<TreeNode*> s; TreeNode* cur=root; while(!s.empty()||cur!=NULL){ if(cur!=NULL){ s.push(cur); cur=cur->left; }else{ cur=s.top(); tmp.push_back(cur->val); s.pop(); cur=cur->right; } } return tmp; }};
阅读全文
0 0
- LintCode -- 二叉树的中序遍历
- lintcode 二叉树的中序遍历
- lintcode:二叉树的中序遍历
- lintcode,二叉树的中序遍历
- LintCode-二叉树的中序遍历
- Lintcode 二叉树的中序遍历
- Lintcode 二叉树的中序遍历
- LintCode 二叉树的中序遍历
- 二叉树的中序遍历-LintCode
- lintcode二叉树的中序遍历
- LintCode 二叉树的中序遍历
- lintcode--二叉树的中序遍历
- lintcode--二叉树的中序遍历
- [LintCode]67.二叉树的中序遍历
- LintCode 67.二叉树的中序遍历
- lintcode-二叉树的中序遍历(非递归)-67
- Lintcode 67 二叉树的中序遍历
- lintcode——二叉树的中序遍历
- APK减少包体大小
- 让客户爱上你的24条建议
- springMVC ,put,delete方法失效
- php更改错误信息
- 对开发者有用的英文网站清单
- [LintCode]67.二叉树的中序遍历
- js获取地理位置的经纬度
- PDO ping 的实例 ,解决mysql has gone的问题
- php5字符串函数总汇(方便查阅)
- vue路由配置
- 中钰睿泓分享:用户体验需要什么内容
- vyos bug
- Java线程锁,以及volatile、synchronized、Lock关键字
- UNIX环境编程学习笔记(5)——文件I/O之fcntl函数访问已打开文件的性质