leetcode94
class Solution {
public:
vector<int> V;
void inOrder(TreeNode* node)
{
if (node != NULL)
{
if (node->left != NULL)
{
inOrder(node->left);
}
V.push_back(node->val);
if (node->right != NULL)
{
inOrder(node->right);
}
}
}
vector<int> inorderTraversal(TreeNode* root) {
inOrder(root);
return V;
}
};
二叉树的中序遍历。
补充python版本实现:
class Solution:
def __init__(self):
self.lists = [] def inOrder(self,root):
if root != None:
if root.left != None:
self.inorderTraversal(root.left)
self.lists.append(root.val)
if root.right != None:
self.inorderTraversal(root.right) def inorderTraversal(self, root: 'TreeNode') -> 'List[int]':
self.inOrder(root)
return self.lists
leetcode94的更多相关文章
- (二叉树 递归) leetcode94. Binary Tree Inorder Traversal
Given a binary tree, return the inorder traversal of its nodes' values. Example: Input: [1,null,2,3] ...
- [Swift]LeetCode94. 二叉树的中序遍历 | Binary Tree Inorder Traversal
Given a binary tree, return the inorder traversal of its nodes' values. Example: Input: [1,null,2,3] ...
- LeetCode94 Binary Tree Inorder Traversal(迭代实现) Java
题目: Given a binary tree, return the inorder traversal of its nodes' values. For example: Given binar ...
- LeetCode94. Binary Tree Inorder Traversal
题目 给定一个二叉树,返回它的中序 遍历. 示例: 输入: [1,null,2,3] 1 \ 2 / 3 输出: [1,3,2] 进阶: 递归算法很简单,你可以通过迭代算法完成吗? 考点 stack ...
- leetcode94 不同的二叉搜索树
solution 1:**动态规划 class Solution { public: int numTrees(int n) { vector<int> g={1,1,2}; for(in ...
- Leetcode94. Binary Tree Inorder Traversal二叉树的中序遍历(两种算法)
给定一个二叉树,返回它的中序 遍历. 示例: 输入: [1,null,2,3] 1 \ 2 / 3 输出: [1,3,2] 进阶: 递归算法很简单,你可以通过迭代算法完成吗? 递归: class So ...
- LeetCode94 二叉树的中序遍历
给定一个二叉树,返回它的中序 遍历. 示例: 输入: [1,null,2,3] 1 \ 2 / 3 输出: [1,3,2] 进阶: 递归算法很简单,你可以通过迭代算法完成吗? /** * ...
- LeetCode 94. 二叉树的中序遍历(Binary Tree Inorder Traversal)
94. 二叉树的中序遍历 94. Binary Tree Inorder Traversal 题目描述 给定一个二叉树,返回它的 中序 遍历. LeetCode94. Binary Tree Inor ...
- Python实现二叉树的非递归中序遍历
思路: 1. 使用一个栈保存结点(列表实现): 2. 如果结点存在,入栈,然后将当前指针指向左子树,直到为空: 3. 当前结点不存在,则出栈栈顶元素,并把当前指针指向栈顶元素的右子树: 4. 栈不为空 ...
随机推荐
- ionic3 使用swiper插件 实现轮播效果
由于app的更新迭代 我需要完成新版本设计图的开发 刚开始就遇到一个问题 首页的banner图需要实现某种效果 而ionic3自带的轮播图效果怎么改都改不到我想要的效果 效果图如下 自动播放 不断 ...
- L337 Should We Relax About Screen Time?
The UK government's plans for regulation of the internet and social media contained a long list of o ...
- yarn不是内部指令 react-native不是内部指令
1.先查看是否全局安装 2.我遇到的是,全局安装了,依然有问题. 昨天装了一个高版本的node,成功后有个黑窗口我点了几个回车,在我的环境变量里加了一大推重复的变量,删除就正常了,如下图是我删完之后的
- mysql 基本函数以及初学语句
创建数据库create database 数据库名: 查看数据库列表show databases; 选择数据库use 数据库名: 删除数据库drop database 数据库名: 创建表CREATE ...
- linux日常命令之三
一.换行符 linux换行符为\n,而windows换行符为\r\n. 因此,linux的原生文本文件,换行符为\n,而windows为\r\n:将linux文件拷贝至windows,换行符保持不变, ...
- PTA——组合数
PTA 7-48 求组合数 #include<stdio.h> double fact(int n); int main() { int m,n; int c; scanf("% ...
- Floodlight1.2+Mininet的安装及使用
直接转载的大神的,亲测Ubuntu16.04版本没问题 https://www.sdnlab.com/19189.html
- msm8909平台JEITA配置和bat-V therm表合入
8909平台的冷热充电温度点是硬件控制的,不能软件控制,目前硬件设置的是0~55度的充电区间. 软件上应该设置的是BTM comparator threshold, 70%(cold)~35%(hot ...
- 深入学习Motan系列(三)——服务发布
袋鼠回头看了看文章,有些啰嗦,争取语音简练,不断提高表达力!袋鼠奋起直追! 注:此篇文章,暂时为了以后时间线排序的需要,暂时发表出来,可是仍然有许多地方需要改写.自己打算把服务端发布,客户端订阅都搞定 ...
- Devexpress Winform MVVM
归纳总结备忘 Devexpress Winform MVVM Practice 前言 MVVM Devexpress 正文 databindings及 UI Triggers Command 委托Co ...