LeetCode 094 Binary Tree Inorder Traversal
方法一:(递归)
class Solution
{
public:
vector<int> inorderTraversal(TreeNode* root)
{
vector<int> v;
inorderTraversalHelp(root, v);
return v;
} void inorderTraversalHelp(TreeNode *root, vector<int>& v)
{
if(root)
{
inorderTraversalHelp(root->left, v);
v.push_back(root->val);
inorderTraversalHelp(root->right, v);
}
}
};
方法二:
LeetCode 094 Binary Tree Inorder Traversal的更多相关文章
- Java for LeetCode 094 Binary Tree Inorder Traversal
解题思路: 中序遍历,左子树-根节点-右子树 JAVA实现如下: public List<Integer> inorderTraversal(TreeNode root) { List&l ...
- [leetcode] 94. Binary Tree Inorder Traversal 二叉树的中序遍历
题目大意 https://leetcode.com/problems/binary-tree-inorder-traversal/description/ 94. Binary Tree Inorde ...
- 49. leetcode 94. Binary Tree Inorder Traversal
94. Binary Tree Inorder Traversal 二叉树的中序遍历 递归方法: 非递归:要借助栈,可以利用C++的stack
- 【LeetCode】Binary Tree Inorder Traversal
Binary Tree Inorder Traversal Total Accepted: 16406 Total Submissions: 47212My Submissions Given a b ...
- leetcode -day29 Binary Tree Inorder Traversal & Restore IP Addresses
1. Binary Tree Inorder Traversal Given a binary tree, return the inorder traversal of its nodes' ...
- [LeetCode]题解(python):094 Binary Tree Inorder Traversal
题目来源 https://leetcode.com/problems/binary-tree-inorder-traversal/ iven a binary tree, return the ino ...
- Leetcode 94. Binary Tree Inorder Traversal
Given a binary tree, return the inorder traversal of its nodes' values. For example:Given binary tre ...
- leetcode 94 Binary Tree Inorder Traversal ----- java
Given a binary tree, return the inorder traversal of its nodes' values. For example:Given binary tre ...
- Java [Leetcode 94]Binary Tree Inorder Traversal
题目描述: Given a binary tree, return the inorder traversal of its nodes' values. For example:Given bina ...
随机推荐
- SQLite3中自增主键归零方法
当SQLite数据库中包含自增列时,会自动建立一个名为 sqlite_sequence 的表.这个表包含两个列:name和seq.name记录自增列所在的表,seq记录当前序号(下一条记录的编号就是当 ...
- jquery 基础-Ajax应用
使用load()方案异步请求数据 调用格式:load(url,[data],[callback]) 参数url为加载服务器地址,可选项data参数为请求时发送的数据,callback参数为数据请求成功 ...
- C++ 消息中间件(MQ4CPP)
MQ4CPP支持: MultiThreading Sockets Cluster Encription Compression Service lookup Message routing 看到MQ4 ...
- icon-font与svg
icon font 使用与svg应用分享 icon font 字体概述 css3增加了@font-face属性,传统的浏览器是通过font-family来设置字体,如果系统里没有的话就用其它字体来代替 ...
- C# in VS
1. DllImport是System.Runtime.InteropServices命名空间下与与非托管相关的一个属性类,负责导出从非托管的dll中导出函数信息,导出的函数在声明时必须有extern ...
- DNS bind子域授权安装
失败经验:rhel 6.x bind 9.8,两台做子域授权,最后失败.原因不详. 改用rhel 5.5, bind 9.3,同样的配置,就成功了.具体记录一下9.3的配置. 安装:采用安装RHEL时 ...
- ubuntu 下安装mysql,以及配置远程登录
安装MysQL 在Ubuntu14.04下安装MySQL比较简单,只需下面这条命令就行了: 1.输入 sudo apt-get install mysql-server 2.继续执行后,需要设定MyS ...
- web安全学习笔记
论坛&资讯 http://www.metasploit.cn http://www.freebuf.com http://www.backtrack.org.cn/ http://www.ha ...
- <java基础学习>RE 基础语法
public class MyFirstJavaProgram{ public static void main(String[] args ){ System.out.println("H ...
- spring IOC装配Bean(注解方式)
1 Spring的注解装配Bean (1) Spring2.5 引入使用注解去定义Bean @Component 描述Spring框架中Bean (2) Spring的框架中提供了与@Componen ...