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 ...
随机推荐
- 老版本db2这里下
https://www-01.ibm.com/support/docview.wss?uid=swg27007053 db2 10.5.10.1.9.x等 下最新FIX版即可
- 关于分布式代码管理工具git
一.安装 Step1 进入官网https://www.git-scm.com/download/下载,然后安装,一直“下一步”即可 Step2 验证是否安装成功,在任意地方右键,菜单中含有Git ...
- learning websocket protocol
websocket的产生背景: 众所周知,Web应用的通信过程通常是客户端通过浏览器发出一个请求,服务器端接收请求后进行处理并返回结果给客户端,客户端浏览器将信息呈现.这种机制对于信息变化不是特别频繁 ...
- 面试北京XX数通总结
软件架构师何志丹 1 总括 1.1 面试时间 2019年1月21号. 1.2 公司概况 员工近20人,其中开发人员6人,全部objectarx(C++),全部老 ...
- java字符串截取指定下标位置的字符串
public class A { public static void main(String[] args) { //定义的字符串 String s = "Hello World" ...
- Mybatis逆向工程自动生成代码(Ubuntu18.04-idea环境)
最近在学习taotao商城项目,有一节是关于mybatis逆向工程的,参考了这个博文,https://blog.csdn.net/yerenyuan_pku/article/details/71909 ...
- 关于angular 的路由title设置
在主模块下 constructor( private router: Router, private activatedRoute: ActivatedRoute, ) {} this.router. ...
- 逐帧动画 两种实现方式 css和js
第一种: css部分: <style> #foxtail{ background: url(../img/foxtail.png) 0 0 no-repeat; width: 156px; ...
- .net回复图片
using System;using System.Collections.Generic;using System.Web;using System.Web.UI;using System.Web. ...
- 背景图片利用backgrond-posintion属性实现不同形式的分割
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...