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. 【Linux】grep命令

    grep 命令 在文件中搜索一个单词,命令会返回一个包含 “match_pattern” 的文本行: grep match_pattern file_name grep "match_pat ...

  2. javascript高级

    数组及操作方法 数组就是一组数据的集合,javascript中,数组里面的数据可以是不同类型的. 定义数组的方法 //对象的实例创建 var aList = new Array(1,2,3); //直 ...

  3. VNPY - windows 安装踩坑记录

    twisted requires PyHamcrest>=, which is not ins grin requires argparse>=1.1, which is not inst ...

  4. Linux中安装tomcat后,window中访问不到tomcat的欢迎界面问题

    首先,可以通过xftp把下载的tomcat的tar.gz包传输到Linux中. 然后进行解压,tar -zxvf   tomcat的压缩包名称(可以使用tab键快速补齐) 解压后,可以使用修改/con ...

  5. nextcloud大文件无法上传

    I think that if u got a small /tmp like i had u cant upload big file…My /tmp = 462M so i can upload ...

  6. GDAL——命令使用专题——gdalsrsinfo命令

    GDAL——命令使用专题——gdalsrsinfo命令  前言 GDAL(Geospatial Data Abstraction Library)是一个在X/MIT许可协议下的开源栅格空间数据转换库. ...

  7. learning makefile 模式规则

  8. Windows10 搭建JAVA环境变量

    系统:Windows10 软件:Java SE 8 配置详细过程 1.“此电脑”,右键→“属性,选择“高级系统设置”(也可从控制面板,系统和安全,系统,找到此页) 2.选择环境变量,再系统环境变量 3 ...

  9. python简介和python工具的选择

    Python 简介 Python 是一个高层次的结合了解释性.编译性.互动性和面向对象的脚本语言. Python 的设计具有很强的可读性,相比其他语言经常使用英文关键字,其他语言的一些标点符号,它具有 ...

  10. 在form表单里上传图片

    需要上传多个图片分别上传,本来提供的工具类里上传一张可以form表单对象实现 后台用MultipartFile file var formdata = new FormData($("#in ...