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 ...
随机推荐
- 2x or 3X的图
2.3倍图处理 bg-image($url) background-image: url($url + "@2x.png") @media (-webkit-min-device- ...
- IntelliJ IDEA2018.3 最新破解方法
IntelliJ IDEA2018.3 最新破解方法 输入 http://idea.java.sx/ 即可,亲测可用.如果资金允许还是希望大家能支持正版,尊重原创 ------------- ...
- js插入HTML代码,渲染页面
<style>td{border:solid 1px #000;}</style> <table><tr id="data_list"&g ...
- 基于mykernel的时间片轮转调度
学号: 363 原创作品,转载请注明出处.本实验资源来源: https://github.com/mengning/linuxkernel/ 一. 实验环境配置 本次实验在实验楼完成: 在实验楼的终端 ...
- As The End of The Year Approaches,The Weighted Blanket Season Begins
Weight blankets are well known for anxiety, insomnia, depression and so on. It is physical therapy, ...
- iSlide——智能图表的用法
iSlide中有一个“智能图表”功能,用于制作漂亮.明了的图表.单击“智能图表”,会弹出一个对话框.从中,可以选择权限.分类和数量级,也可以直接搜索. 实战: 我想做一个全班不同年级近视人数的统计报, ...
- java 8 Lambda
警告: 初学者随笔, 请关闭此网页, 以免浪费你的时间
- <input>标签单、复选相关查询地址
http://www.w3school.com.cn/tags/tag_input.asp 以下是相关示例,转载 lfx_web: <html><head><script ...
- python学习------迭代器协议和生成器
一.递归和迭代 递归:自己调用自己 举例解释:问路 A问B康明网络科技怎么走,B说我不是很清楚,我帮你问问C,C说我也不知道.我问问D,D说 就在兴隆.之后D返回结果给C,C返回结果给B,B返回结 ...
- 如何推进企业流程体系建设?_K2 BPM
推进全集团统一的流程体系为什么比想象的难? 很多企业在推进全集团的流程管理过程中,经常会有一种“望山跑死马”的感觉.“各成员公司都建立起与集团公司统一的流程管理体系”,看似很简单一件事情,但没有经过良 ...