/**
* Definition of TreeNode:
* class TreeNode {
* public:
* int val;
* TreeNode *left, *right;
* TreeNode(int val) {
* this->val = val;
* this->left = this->right = NULL;
* }
* }
*/
//递归方法
class Solution {
/**
* @param root: The root of binary tree.
* @return: Inorder in vector which contains node values.
*/
public: void inorder(TreeNode *root, vector<int> &result) {
if (root->left != NULL) {
inorder(root->left, result);
} result.push_back(root->val); if (root->right != NULL) {
inorder(root->right, result);
} } vector<int> inorderTraversal(TreeNode *root) {
// write your code here
vector<int> result;
if (root == NULL)
return result;
inorder(root, result);
return result;
}
};

lintcode 二叉树中序遍历的更多相关文章

  1. 二叉树中序遍历 (C语言实现)

    在计算机科学中,树是一种重要的非线性数据结构,直观地看,它是数据元素(在树中称为结点)按分支关系组织起来的结构.二叉树是每个节点最多有两个子树的有序树.通常子树被称作“左子树”(left subtre ...

  2. 94 Binary Tree Inorder Traversal(二叉树中序遍历Medium)

    题目意思:二叉树中序遍历,结果存在vector<int>中 解题思路:迭代 迭代实现: /** * Definition for a binary tree node. * struct ...

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

    Given a binary tree, return the inorder traversal of its nodes' values. Example: Input: [1,null,2,3] ...

  4. lintcode.67 二叉树中序遍历

    二叉树的中序遍历    描述 笔记 数据 评测 给出一棵二叉树,返回其中序遍历 您在真实的面试中是否遇到过这个题? Yes 样例 给出二叉树 {1,#,2,3}, 1 \ 2 / 3 返回 [1,3, ...

  5. 10.26最后的模拟DAY2 改造二叉树[中序遍历+严格递增的最长不下降子序列]

    改造二叉树 [题目描述] 小Y在学树论时看到了有关二叉树的介绍:在计算机科学中,二叉树是每个结点最多有两个子结点的有序树.通常子结点被称作“左孩子”和“右孩子”.二叉树被用作二叉搜索树和二叉堆.随后他 ...

  6. LeetCode:94_Binary Tree Inorder Traversal | 二叉树中序遍历 | Medium

    题目:Binary Tree Inorder Traversal 二叉树的中序遍历,和前序.中序一样的处理方式,代码见下: struct TreeNode { int val; TreeNode* l ...

  7. [Leetcode] Binary tree inorder traversal二叉树中序遍历

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

  8. leetCode 94.Binary Tree Inorder Traversal(二叉树中序遍历) 解题思路和方法

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

  9. 二叉树中序遍历,先序遍历,后序遍历(递归栈,非递归栈,Morris Traversal)

    例题 中序遍历94. Binary Tree Inorder Traversal 先序遍历144. Binary Tree Preorder Traversal 后序遍历145. Binary Tre ...

随机推荐

  1. M4修改外部晶振8M和25M晶振的方法

    共计修改三个参数: 1.HSE_VALUE   具体位置在stm32f4xx.h中 2.PLL_M          具体位置在system_stm32f4xx.c中 3.Keil编译器 工程的Opt ...

  2. tomcat解析

    tomat是一个servlet容器,来处理http请求.在平时的使用中我们都会再浏览器中输入http地址来访问服务资源,比如格式http://host[":"port][abs_p ...

  3. Web—02-轻松理解css

    CSS基本语法以及页面引用 CSS基本语法 css的定义方法是: 选择器 { 属性:值; 属性:值; 属性:值;} 选择器是将样式和页面元素关联起来的名称,属性是希望设置的样式属性每个属性有一个或多个 ...

  4. oracle系列(三)表操作基础

    支持的数据类型: 字符型char 定长 最大2000varchar2() 变长 最大4000clob 字符型大对象 最大4G 数字型number范围 -10的38次方到10的+38次方;number( ...

  5. Crash for small compressed texture on some Android device

    I created a full white texture with 4x4 size. Unity requires that compressed texture size should be ...

  6. android软件开发之TextView控件常用属性

    TextView控件 text属性,设置显示的文本 textColor:设置文本颜色 textSize:设置文本字体大小 autoLink:设置文本为电话,URL连接等的时候是否显示为可点击的链接 c ...

  7. 用原生JS写一个网页版的2048小游戏(兼容移动端)

    这个游戏JS部分全都是用原生JS代码写的,加有少量的CSS3动画,并简单的兼容了一下移动端. 先看一下在线的demo:https://yuan-yiming.github.io/2048-online ...

  8. Spring : Spring Security

    ==========================================================================spring-security-过滤器: 顶级Fil ...

  9. day 26 网络知识 01

    一.    c/s 架构: 客户端(client)/服务端(server)架构       服务端: 提供服务的      客户端: 享受服务的     B/S 架构:浏览器(browser)/服务端 ...

  10. 10种简单的Java性能优化

    你是否正打算优化hashCode()方法?是否想要绕开正则表达式?Lukas Eder介绍了很多简单方便的性能优化小贴士以及扩展程序性能的技巧. 最近“全网域(Web Scale)”一词被炒得火热,人 ...