Deepest left leaf node in a binary tree
Recursion
- selfcontained recursion
- global variables outside of recursion
Recursion Design
- Whenever reach to a qualified node, record the node reference and level for that node
- if meet next qualified node, compare the level, if larger, refresh the global node reference and level.
- 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的更多相关文章
- LeetCode 671. 二叉树中第二小的节点(Second Minimum Node In a Binary Tree) 9
671. 二叉树中第二小的节点 671. Second Minimum Node In a Binary Tree 题目描述 给定一个非空特殊的二叉树,每个节点都是正数,并且每个节点的子节点数量只能为 ...
- 【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 ...
- [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 描述 ...
- Python 解LeetCode:671. Second Minimum Node In a Binary Tree
题目在这里,要求一个二叉树的倒数第二个小的值.二叉树的特点是父节点的值会小于子节点的值,父节点要么没有子节点,要不左右孩子节点都有. 分析一下,根据定义,跟节点的值肯定是二叉树中最小的值,剩下的只需要 ...
- [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 ...
- 【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 ...
- [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 ...
- LeetCode算法题-Second Minimum Node In a Binary Tree(Java实现)
这是悦乐书的第285次更新,第302篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第153题(顺位题号是671).给定非空的特殊二叉树,其由具有非负值的节点组成,其中该树 ...
- [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 ...
随机推荐
- _proto_理解
一个对象就是一个属性集合,并拥有一个独立的prototype(原型)对象.这个prototype可以是一个对象或 者null. 一个对象的prototype是以内部的[[Prototype]]属性来引 ...
- Angular7.1.4+Typescript3.1框架学习(一)
起因:学习ionic4之前先学习下angular+ts 以win10为开发平台:当前最新版本为angular7;根据官网资料做如下总结: 1. angular安装 前提:Node.js 的 8.x 或 ...
- springBoot 随笔(二)
此文为springBoot 结合 thymeleaf ,解析后台接口数据展示到html页面 基于 springBoot(一)工程. 1/ 引用 thymeleaf 组件依赖 <!-- depen ...
- 关于:无法创建链接服务器 "ORCL" 的 OLE DB 访问接口 "OraOLEDB.Oracle" 的实例 (错误:7302)
本人接触和使用Oracle数据库才有一个季度的时间,问题比较白,大神请无视本文. 环境: 1.数据服务器,windows2008R2,Oracle11g 2.报表服务器,windows2008R2,S ...
- GoLand配置数据库、远程host以及远程调试
GoLand配置MySQL数据库: (1)右侧栏 -> Database -> +添加 (2)选择MySQL (3)修改Name -> Comment(可选) (4)选择MySQL版 ...
- arp嗅探(windows)
本次实验环境:windows本次实验工具:cain汉化版1.点击配置,嗅探器里选一个适配器,点击确定. 2.点击 3.扫描mac地址 4.点击ARP->嗅探器->添加到列表5.点击开始嗅探 ...
- 语法、id和class选择器、创建、
一. 1.CSS规则由两个主要部分构成:选择器,以及一条或多条声明(每条声明由一个属性和一个值构成,属性和值被冒号分开). 2.声明以分号“:”结束,生命组用大括号“{}”括起来. [示例:p {co ...
- elasticsearch基本使用
elasticsearch 是java对lucence的封装,所以需要事先安装java. 它适用于全文索引,便捷的分布式,主要原理就是倒排索引.一般搜索某个关键字,是通过在一篇篇文章中查找这个关键字, ...
- python pexpect包的一些用法
转自:https://www.jianshu.com/p/cfd163200d12 mark一下,原文中写的挺详细
- rnn应用
Weather Recognition plays an important role in our daily lives and many computer vision applications ...