Java for LeetCode 094 Binary Tree Inorder Traversal
解题思路:
中序遍历,左子树-根节点-右子树
JAVA实现如下:
public List<Integer> inorderTraversal(TreeNode root) {
List<Integer> list = new ArrayList<Integer>();
if(root==null)
return list;
if (root.left != null)
list.addAll(inorderTraversal(root.left));
list.add(root.val);
if (root.right != null)
list.addAll(inorderTraversal(root.right));
return list;
}
Java for LeetCode 094 Binary Tree Inorder Traversal的更多相关文章
- LeetCode 094 Binary Tree Inorder Traversal
方法一:(递归) class Solution { public: vector<int> inorderTraversal(TreeNode* root) { vector<int ...
- [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 ----- 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 ...
- Leetcode 94. Binary Tree Inorder Traversal
Given a binary tree, return the inorder traversal of its nodes' values. For example:Given binary tre ...
随机推荐
- [转]使用Wireshark来检测一次HTTP连接过程
Wireshark是一个类似tcpdump的嗅探软件,界面更人性化一些,今天我用它来检测一次HTTP连接过程. 安装好之后,先配置一下,选择Capture->Options,先设定你要嗅探的网络 ...
- 如何让你的网页加载时间降低到 1s 内
当初分析了定宽高值和定宽高比这两种常见的图片延迟加载场景,也介绍了他们的应对方案,还做了一点技术选型的工作. 经过一段时间的项目实践,在先前方案的基础上又做了很多深入的优化工作.最终将好奇心日报的网页 ...
- yield理解
http://www.jianshu.com/p/d09778f4e055 从yield处返回一个值,下次从yield后开始执行
- 将输入流InputStream转换为String
public static String convertStreamToString(InputStream is) { /* * To convert the InputStream to Stri ...
- vim g s 替换区别
vim g s 替换区别 PS:一篇好文收藏备用,今天用它解决了一个大问题. 发信人: vale (浅谷), 信区: VIM标 题: global命令详解 发信站: 水木社区 (Fri Ju ...
- PocketBeagle 初高级设置
前言 原创文章,转载引用务必注明链接,水平有限,如有疏漏,欢迎指正.本文使用markdown标记语言写成,为获得最好的阅读体验,请访问我的博客原文. 1. PocketBeagle Summary ...
- C# 读取Excel中的数据
#region 读取Excel中的数据 /// <summary> /// 读取Excel中的数据 /// </summary> /// <param name=&quo ...
- 设计模式之Protocol实现代理模式
使用场合 使用步骤 不使用protocol实现代理 使用protocol实现代理 一.使用场合 A想让B帮忙,就让B代理 A想通知B发生了一些事情,或者传一些数据给B 观察者模式 二.使用步骤 定义一 ...
- linux链接外网手动设置
/etc/sysconfig/network-scripts/ifcfg-eth0 设置IP网关等参数 DEVICE=eth0HWADDR=00:0C:29:C5:43:34TYPE=Etherne ...
- 聊聊高并发(三十九)解析java.util.concurrent各个组件(十五) 理解ExecutorService接口的设计
上一篇讲了Executor接口的设计,目的是将任务的运行和任务的提交解耦.能够隐藏任务的运行策略.这篇说说ExecutorService接口.它扩展了Executor接口,对Executor的生命周期 ...