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. react .net core 发布 Access-Control-Allow-Origin Cors

    本案例用IIS部署 1. 在react上先publish: npm run build 生成了build文件,在此文件里添加web.config,注意httpProtocol是用来跨域的. <? ...

  2. 12、类成员访问修饰符public/private/producted/readonly

    1.private 类的私有成员 private 类的私有成员,只能在内部访问,在外部访问不到,无法被继承,我们可以将不需要被外部修改的定义为私有的 私有成员,只能在内部访问,在外部访问不到 priv ...

  3. UIPath Level 2&3

    Level 3 走了很多弯路,但是学到了很多东西,贴一个Level3的吧,其他的省略了 认认真真独立做完Level3的两个POC,相信你对UIPath的理解会更深入一步 晚安,祝各位中秋节快乐!

  4. leetcode 链表相关

    1.给出两个 非空 的链表用来表示两个非负的整数.其中,它们各自的位数是按照 逆序 的方式存储的,并且它们的每个节点只能存储 一位 数字. 如果,我们将这两个数相加起来,则会返回一个新的链表来表示它们 ...

  5. 共识机制:AngelToken技术的根基

    共识机制是区块链技术的一个核心问题,它决定了区块链中区块的生成法则,保证了各节点的诚实性.账本的容错性和系统的稳健性. 常用的共识机制主要有 PoW.PoS.DPoS.Paxos.PBFT等. 基于区 ...

  6. 电脑小白和ta的小白电脑——Git的使用

    简单介绍Git的安装和基本指令,不要抱太大希望QAQ 看完这篇博客,最多学会如何向远程库上传和从远程库拉取项目,复杂功能要 做中学! (一)Git的安装 1.下载 (1)官网下载地址: https:/ ...

  7. 记一次 SSM 分页

    1.实体层(entity,pojo,domain) package com.entity; import java.io.Serializable; private int totalCount; / ...

  8. ssh整合报错严重: Context initialization failed org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'xxx'

    错误描述:eclipse整合ssh的时候 报不能创建名字为xxx的对象 信息: Destroying singletons in org.springframework.beans.factory.s ...

  9. linux ubuntu 安装后没有root密码

    终端中输入:sudo passwd root 此时重新设置原登录用户的密码. 设置成功后在终端继续输入: su root 则出现#号,原用户名得到root权限.此时可以进行超级用户操作.

  10. 初写Linux脚本坑记录

    1.为变量赋值时=前后一定没有空格. 2.赋值时变量为xx,读取才是$xx.如赋值是$xx,则报语法错误.参考 http://www.jb51.net/article/52375.htm 3.脚本每句 ...