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 ...
随机推荐
- NOIP 2014 D2T3 解方程 Hash大法好
题目大意:给定高次方程an*x^n+...+a1*x^1+a0*x^0=0 求[1,m]区间内有多少个整数根 ai<=10^10000.m<=100W 懒得高精,考场上写的long dou ...
- Linux 设备驱动模型
Linux系统将设备和驱动归一到设备驱动模型中了来管理 设备驱动程序功能: 1,对硬件设备初始化和释放 2,对设备进行管理,包括实参设置,以及提供对设备的统一操作接口 3,读取应用程序传递给设备文件的 ...
- mybatis配置mapperLocations多个路径
<property name="mapperLocations"> <array> <value>classpath*:/mybatis-con ...
- 转: java服务器端成长指南
from: http://m.blog.csdn.net/article/details?id=45797155 前言 这是一份针对新手的服务端开发入门与进阶指南.遇到问题及时问你的 mentor ...
- Flak快速上手
本文介绍如何上手 Flask . 这里假定你已经安装好了 Flask ,否则请先阅读< 安装>. 如果已安装好Flask,通过以下命令查看 一个简单的例子: from flask impo ...
- centos-64整合nginx和tomcat
centos-64整合nginx和tomcat 分类: Linux 2013-04-25 10:41 128人阅读 评论(0) 收藏 举报 1.安装wget和依赖包 yum install wget ...
- phpQuery—基于jQuery的PHP实现(转)
Query的选择器之强大是有目共睹的,phpQuery 让php也拥有了这样的能力,它就相当于服务端的jQuery. 先来看看官方简介: phpQuery is a server-side, chai ...
- Java 调用OPENOFFIC 转换文档类型
public static void office2PDF(String sourceFile, String destFile) { try { File inputFile = new File( ...
- ie6中利用jquery居中
1.利用jquery居中代码 <script type="text/javascript"> $hwidth=parseInt($(window).width()); ...
- jdbc 链接池的优化
package cn.itcast.jdbc.datasourse; import java.sql.Connection;import java.sql.DriverManager;import j ...