Given a binary tree, return the inorder traversal of its nodes' values.

Example:

Input: [1,null,2,3]
1
\
2
/
3 Output: [1,3,2]

Follow up: Recursive solution is trivial, could you do it iteratively?

Recursive solution

/**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) { val = x; }
* }
*/
class Solution {
List<Integer> res = new ArrayList<Integer>();
public List<Integer> inorderTraversal(TreeNode root) {
//inorder traveral : left root right
inorder( root);
return res;
}
void inorder(TreeNode node){
if(node==null) return;
inorder(node.left);
res.add(node.val);
inorder(node.right); }
}

follow up questions

94. Binary Tree Inorder Traversal(inorder ) ***(to be continue)easy的更多相关文章

  1. 49. leetcode 94. Binary Tree Inorder Traversal

    94. Binary Tree Inorder Traversal    二叉树的中序遍历 递归方法: 非递归:要借助栈,可以利用C++的stack

  2. [leetcode] 94. Binary Tree Inorder Traversal 二叉树的中序遍历

    题目大意 https://leetcode.com/problems/binary-tree-inorder-traversal/description/ 94. Binary Tree Inorde ...

  3. 二叉树前序、中序、后序非递归遍历 144. Binary Tree Preorder Traversal 、 94. Binary Tree Inorder Traversal 、145. Binary Tree Postorder Traversal 、173. Binary Search Tree Iterator

    144. Binary Tree Preorder Traversal 前序的非递归遍历:用堆来实现 如果把这个代码改成先向堆存储左节点再存储右节点,就变成了每一行从右向左打印 如果用队列替代堆,并且 ...

  4. 刷题94. Binary Tree Inorder Traversal

    一.题目说明 题目94. Binary Tree Inorder Traversal,给一个二叉树,返回中序遍历序列.题目难度是Medium! 二.我的解答 用递归遍历,学过数据结构的应该都可以实现. ...

  5. Leetcode 94. Binary Tree Inorder Traversal

    Given a binary tree, return the inorder traversal of its nodes' values. For example:Given binary tre ...

  6. 94. Binary Tree Inorder Traversal

    Given a binary tree, return the inorder traversal of its nodes' values. For example:Given binary tre ...

  7. leetcode 94 Binary Tree Inorder Traversal ----- java

    Given a binary tree, return the inorder traversal of its nodes' values. For example:Given binary tre ...

  8. Java [Leetcode 94]Binary Tree Inorder Traversal

    题目描述: Given a binary tree, return the inorder traversal of its nodes' values. For example:Given bina ...

  9. Leetcode 94. Binary Tree Inorder Traversal (中序遍历二叉树)

    Given a binary tree, return the inorder traversal of its nodes' values. For example: Given binary tr ...

  10. 【LeetCode】94. Binary Tree Inorder Traversal

    题目: Given a binary tree, return the inorder traversal of its nodes' values. For example:Given binary ...

随机推荐

  1. Experimental Educational Round: VolBIT Formulas Blitz K

    Description IT City company developing computer games decided to upgrade its way to reward its emplo ...

  2. Codeforces Round #340 (Div. 2) C

    Description A flowerbed has many flowers and two fountains. You can adjust the water pressure and se ...

  3. php5 编译安装

    #!/bin/bash######################################## File Name: php.sh# Version: V1.0# Author: sun yu ...

  4. django基础学习

    {{forloop.counter}}  这是html的自增序号 GET请求可以直接从URL中获取信息,POST请求不可以,可以把信息藏到一个隐藏的input文本框中 orm 的概念就是对象关系映射 ...

  5. Jenkins自动化CI CD流水线之8--流水线自动化发布Java项目

    一.前提 插件:Maven Integration plugin 环境: maven.tomcat 用的博客系统代码: git clone https://github.com/b3log/solo. ...

  6. Java 初始化和清理

    初始化和清理是影响代码安全的两个重要因素. 一.初始化 1. 方法重载 构造器与类名相同,成为强制重载方法名的原因之一.重载规则:每个重载的方法必须拥有独一无二的参数类型列表.不能根据返回值来区分重载 ...

  7. docker基本命令日志

    docker run - Run a command in a new container 启动一个新的容器,一般在docker pull之后首次运行此image -i 保持stdout打开 -t 打 ...

  8. 【ACM】蛇形填数 - 逻辑怪

    蛇形填数 时间限制:3000 ms  |  内存限制:65535 KB 难度:3   描述 在n*n方陈里填入1,2,...,n*n,要求填成蛇形.例如n=4时方陈为:10 11 12 19 16 1 ...

  9. 转 PyCharm 进行调试 以及怎么熟悉一个已经成熟的项目的代码和断点 以及 jetBrains pycharm快捷键

    https://blog.csdn.net/guider2334/rss/list Ctrl + Q 现实document视图,查看选择元素的详细信息        (重要) Ctrl + Alt + ...

  10. Django权限1

    1.权限,说白了就是你有资格访问这个网址,而别人每一资格:你有资格进行增删改查,而别人只有查的权限 2.新建是3张表: #用户表 class User(models.Model): name = mo ...