Binary Tree Inorder Traversal
2015-07-10 16:41
253 查看
https://leetcode.com/problems/binary-tree-inorder-traversal/
递归中序遍历
递归中序遍历
/** * 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: vector<int> inorderTraversal(TreeNode* root) { vector<int> res; inorderVisit(root,res); return res; } void inorderVisit(TreeNode * temp,vector<int>& res) { if(temp==NULL) return; if(temp->left!=NULL) inorderVisit(temp->left,res); res.push_back(temp->val); if(temp->right!=NULL) inorderVisit(temp->right,res); } };
相关文章推荐
- Windows Server 2012/win8 iis8 上安装 asp.net 4.5 当时用了mvc5 .net framework 4.5 所以得装下
- 微信公共平台消息回复类
- HashSet<T>类
- 【再思考】1010. Radix (25)
- android使用xml实现虚线效果
- 树上操作 解题报告
- 自动回复微信消息
- 【Java】汉诺塔问题
- CodeForces 555E Case of Computer Network
- SQL Server查看所有表大小,所占空间
- CocoaPods安装和使用教程-2
- Oracle学习(十八)之控制文件、日志文件、数据文件及配置文件管理总结
- C &&Linux 下简单实现单词统计
- 瞎子摸牌问题
- Linux中link,unlink,close,fclose详解
- 微软公布Win10预览版KMS客户端安装密钥 不可激活零售版
- ubuntu下配置jdk环境变量和安装tomcat7
- 微软公布Win10预览版KMS客户端安装密钥 不可激活零售版
- GRE写作必备句型
- shell入门之流程控制语句