UUBlog

UUBlog

  • Home
  • Categories32
  • Archives117
  • Tags116
  • About
  • Table of Contents
  • Overview

尹安灿

117 posts
32 categories
116 tags
0%

Python求二叉树最大深度

Posted on 2017-11-09 Edited on 2022-01-29 In python , algorithms

继前面Python二叉树递归和遍历

二叉树图

binary tree

1
2
3
4
5
6
def max_depth(node):
if not node:
return 0
ldepth = max_depth(node.left)
rdepth = max_depth(node.right)
return max(ldepth,rdepth) + 1

结果:4

关注公众号 尹安灿

# python # binary tree # max depth
Crontab执行命令失败 手工执行成功
Linux挂载NTFS但是不可写 Read-only
粤ICP备17061759号
© 2022 尹安灿
Powered by Hexo & NexT.Gemini