Recursion

  1. selfcontained recursion
  2. global variables outside of recursion

Recursion Design 

  1. Whenever reach to a qualified node, record the node reference and level for that node
  2. if meet next qualified node, compare the level, if larger, refresh the global node reference and level.
  3. Recursively do 1 and 2 recursively for left tree and right tree

Data Structure

    public class AVLTreeNode
{
public int data
{
get;
set;
} public AVLTreeNode leftChild
{
get;
set;
} public AVLTreeNode rightChild
{
get;
set;
} public int height
{
get;
set;
} public AVLTreeNode(int data)
{
this.data = data;
this.height = ;
}
}

Source Code

   public class Result
{
public int MaxHight
{
get;
set;
} public AVLTreeNode ResultNode
{
get;
set;
}
} // Find deepest left node
public void FindDeepestLeftNode(AVLTreeNode node, bool isLeft, int height, Result result)
{
if (node == null)
{
return;
} if (isLeft)
{
if (node.leftChild == null && node.rightChild == null && height > result.MaxHight)
{
result.ResultNode = node;
result.MaxHight = height;
}
} FindDeepestLeftNode(node.leftChild, true, height + , result);
FindDeepestLeftNode(node.rightChild, false, height + , result);
} public AVLTreeNode GetDeepestLeftNode()
{
Result result = new Result()
{
MaxHight = ,
ResultNode = null
}; FindDeepestLeftNode(root, true, , result);
return result.ResultNode;
}

Complexity

Time complexity is O(N)

Space complexity is O(N)

Deepest left leaf node in a binary tree的更多相关文章

  1. LeetCode 671. 二叉树中第二小的节点(Second Minimum Node In a Binary Tree) 9

    671. 二叉树中第二小的节点 671. Second Minimum Node In a Binary Tree 题目描述 给定一个非空特殊的二叉树,每个节点都是正数,并且每个节点的子节点数量只能为 ...

  2. 【Leetcode_easy】671. Second Minimum Node In a Binary Tree

    problem 671. Second Minimum Node In a Binary Tree 参考 1. Leetcode_easy_671. Second Minimum Node In a ...

  3. [leetcode]1379. Find a Corresponding Node of a Binary Tree in a Clone of That Tree

    [leetcode]1379. Find a Corresponding Node of a Binary Tree in a Clone of That Tree 链接 leetcode 描述    ...

  4. Python 解LeetCode:671. Second Minimum Node In a Binary Tree

    题目在这里,要求一个二叉树的倒数第二个小的值.二叉树的特点是父节点的值会小于子节点的值,父节点要么没有子节点,要不左右孩子节点都有. 分析一下,根据定义,跟节点的值肯定是二叉树中最小的值,剩下的只需要 ...

  5. [LeetCode] Second Minimum Node In a Binary Tree 二叉树中第二小的结点

    Given a non-empty special binary tree consisting of nodes with the non-negative value, where each no ...

  6. 【easy】671. Second Minimum Node In a Binary Tree

    Given a non-empty special binary tree consisting of nodes with the non-negative value, where each no ...

  7. [Swift]LeetCode671. 二叉树中第二小的节点 | Second Minimum Node In a Binary Tree

    Given a non-empty special binary tree consisting of nodes with the non-negative value, where each no ...

  8. LeetCode算法题-Second Minimum Node In a Binary Tree(Java实现)

    这是悦乐书的第285次更新,第302篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第153题(顺位题号是671).给定非空的特殊二叉树,其由具有非负值的节点组成,其中该树 ...

  9. [LeetCode&Python] Problem 671. Second Minimum Node In a Binary Tree

    Given a non-empty special binary tree consisting of nodes with the non-negative value, where each no ...

随机推荐

  1. 数据结构与算法之PHP排序算法(桶排序)

    一.基本思想 桶排序是将待排序的数据分割成许多buckets,然后每个bucket各自排序,或用不同的排序算法,或者递归的使用bucket sort算法.也是典型的分而治之(divide-and-co ...

  2. 微信小程序电商实战(-)商城首页

    首先在app.json中配置页面和底部tabbar { "pages":[ "pages/index/index", "pages/kind/kind ...

  3. RK3288 GPIO

    简介GPIO, 全称 General-Purpose Input/Output(通用输入输出),是一种软件运行期间能够动态配置和控制的通用引脚.RK3288有9组 GPIO bank: GPIO0,G ...

  4. Qt 比对TreeItem节点

    void TreeModel::settingsUpdate(const QStringList &lines){ QList<TreeItem*> parents; TreeIt ...

  5. 构建微服务:Spring boot 入门篇

    什么是Spring Boot Spring Boot 是由 Pivotal 团队提供的全新框架,其设计目的是用来简化新 Spring 应用的初始搭建以及开发过程.该框架使用了特定的方式来进行配置,从而 ...

  6. goodsSearch初始化选中代码

    watch: { selectGoodsList (val) { let list = [] val.forEach(item => { this.goodsList.forEach((tag, ...

  7. spring(IOC)动态代理

    姓名:黄于霞      班级:软件151 1.引入Spring IOC的核心jar包,创建IOC的配置文件beans.xml,内容如下: 1 <?xml version="1.0&qu ...

  8. 用工具metaseeker写简单爬虫(1)

    1.下载metaseeker(一款比较实用的网站数据采集程序) 2.将所要爬取的网页复制到网址里,按回车.我选择的是当当网新书排行榜页面,标2的地方表示已经导入到软件里了. 3.命名主题,查重,查看是 ...

  9. tensorflow estimator API小栗子

    TensorFlow的高级机器学习API(tf.estimator)可以轻松配置,训练和评估各种机器学习模型. 在本教程中,您将使用tf.estimator构建一个神经网络分类器,并在Iris数据集上 ...

  10. 活代码LINQ——01

    序言 此系列的所有代码都是运行在Win 7 64位 + Visual Basic 2008 Express Edition的环境中 之所以学习List集合类,是因为我们先前学习的数组自身的缺陷: 1. ...