LeetCode OJ 94. Binary Tree Inorder Traversal
Given a binary tree, return the inorder traversal of its nodes' values.
For example:
Given binary tree [1,null,2,3],
1
\
2
/
3
return [1,3,2].
Note: Recursive solution is trivial, could you do it iteratively?
Subscribe to see which companies asked this question
解答
原来那个returnSize是拿来返回产生的中序遍历的数组大小用的……数组下标从0开始计算……
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* struct TreeNode *left;
* struct TreeNode *right;
* };
*/
/**
* Return an array of size *returnSize.
* Note: The returned array must be malloced, assume caller calls free().
*/
int* inorderTraversal(struct TreeNode* root, int* returnSize) {
], top = -, i = ;
);
!= top||NULL != root){
while(NULL != root){
stack[++top] = root;
root = root->left;
}
root = stack[top--];
return_array[i++] = root->val;
root = root->right;
}
*returnSize = i;
return return_array;
}
LeetCode OJ 94. Binary Tree Inorder Traversal的更多相关文章
- 【LeetCode】94. Binary Tree Inorder Traversal (3 solutions)
Binary Tree Inorder Traversal Given a binary tree, return the inorder traversal of its nodes' values ...
- 【LeetCode】94. Binary Tree Inorder Traversal
题目: Given a binary tree, return the inorder traversal of its nodes' values. For example:Given binary ...
- 【一天一道LeetCode】#94. Binary Tree Inorder Traversal
一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Given a ...
- 【LeetCode】94. Binary Tree Inorder Traversal 解题报告(Python&C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 解题方法 递归 迭代 日期 题目地址:https://leetcode.c ...
- LeetCode OJ: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 二叉树的中序遍历
题目大意 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
- 二叉树前序、中序、后序非递归遍历 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 前序的非递归遍历:用堆来实现 如果把这个代码改成先向堆存储左节点再存储右节点,就变成了每一行从右向左打印 如果用队列替代堆,并且 ...
- 刷题94. Binary Tree Inorder Traversal
一.题目说明 题目94. Binary Tree Inorder Traversal,给一个二叉树,返回中序遍历序列.题目难度是Medium! 二.我的解答 用递归遍历,学过数据结构的应该都可以实现. ...
随机推荐
- SpringMVC 注解详解
SpringMVC常用注解说明 @Bean, @Configuration表示基于Java配置的类@Bean除了配置在@Configuration,也可以在@Component定义,此时没有特殊意义, ...
- webpack实现scss编译配置
1.webpack.start.js: var webpack = require('webpack'); var SpritesmithPlugin = require('webpack-sprit ...
- 在javascript中toString 和valueOf的区别
1.toString()方法:主要用于Array.Boolean.Date.Error.Function.Number等对象转化为字符串形式.日期类的toString()方法返回一个可读的日期和字符串 ...
- jQuery操作DOM节点的方法总结
1.parent():获得当前匹配元素集合中每个元素的父元素,该方法只会向上一级对 DOM 树进行遍历 $('li.item-a').parent().css('background-color', ...
- css实现三角形标
.iszb{ position: absolute;top: -75px;right:-75px;text-align: center;color: red; width: 150px;height: ...
- linux命令之vi文本编辑器
vi filename :打开或新建文件,并将光标置于第一行首 按i,开始输入(insert) d删除整行 u 撤销上一步的操作Ctrl+r 恢复上一步被撤销的操作 ESC退出输入 按ESC键 跳 ...
- isNAN的使用方法及介绍
NaN为 Not a Number isNaN()函数在接到一个值后,会尝试将这个值转换为数值. alert(isNaN(NaN)); //true alert(isNaN(25)); //false ...
- 转)mybatis实战教程(mybatis in action),mybatis入门到精通
mybatis实战教程(mybatis in action),mybatis入门到精通 http://limingnihao.iteye.com/blog/781671 http://blog.csd ...
- angularjs探秘<二>表达式、指令、数据绑定
距离第一篇笔记好久了,抽空把angular的笔记梳理梳理. ng-init:初始化指令,这里可以声明变量,且变量不用指定数据类型(类似js中的var用法). 数值变量与字符串相加默认做字符串拼接运算. ...
- android 开发 实现一个带图片Image的ListView
注意:这种实现方法不是实现ListView的最优方法,只是希望通过练习了解ListView的实现原理 思维路线: 1.创建drawable文件夹将要使用的图片导入进去 2.写一个类,用于存放图片ID数 ...