博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
codetest
阅读量:6894 次
发布时间:2019-06-27

本文共 1592 字,大约阅读时间需要 5 分钟。

测试代码表现

1 def depth_of_tree(tree): #This is the recursive function to find the depth of binary tree.  2     if tree is None:  3         return 0  4     else:  5         depth_l_tree = depth_of_tree(tree.left)  6         depth_r_tree = depth_of_tree(tree.right)  7         if depth_l_tree > depth_r_tree:  8             return 1 + depth_l_tree  9         else: 10             return 1 + depth_r_tree 11  12  13 def is_full_binary_tree(tree): # This functions returns that is it full binary tree or not? 14     if tree is None: 15         return True 16     if (tree.left is None) and (tree.right is None): 17         return True 18     if (tree.left is not None) and (tree.right is not None): 19         return (is_full_binary_tree(tree.left) and is_full_binary_tree(tree.right)) 20     else: 21         return False
 
 
def depth_of_tree(tree): #This is the recursive function to find the depth of binary tree.    if tree is None:        return 0    else:        depth_l_tree = depth_of_tree(tree.left)        depth_r_tree = depth_of_tree(tree.right)        if depth_l_tree > depth_r_tree:            return 1 + depth_l_tree        else:            return 1 + depth_r_treedef is_full_binary_tree(tree): # This functions returns that is it full binary tree or not?    if tree is None:        return True    if (tree.left is None) and (tree.right is None):        return True    if (tree.left is not None) and (tree.right is not None):        return (is_full_binary_tree(tree.left) and is_full_binary_tree(tree.right))    else:        return False

转载于:https://www.cnblogs.com/binyang/p/10897515.html

你可能感兴趣的文章
7.Spring Boot配置文件application.yml
查看>>
计算学校周次,亲测成功!
查看>>
Centos 7 可安装 mysql5.7
查看>>
雷神2—狂热视觉震撼
查看>>
node.js实现多图片上传
查看>>
could not bind to address 0.0.0.0:443 no listening sockets available, shutting d
查看>>
Node.js 开发相关
查看>>
JFinal源码--获取表单数据
查看>>
JSONP安全防范解决方案新思路
查看>>
Web 开发最有用的50款 jQuery 插件集锦——《综合篇》
查看>>
import com.sun.image.codec.jpeg.JPEGCodec不通过 找不到包
查看>>
adrci中的purge
查看>>
前台对Seajs的用法个人见解
查看>>
java中的队列同步器AQS -- AbstractQueuedSynchronizer
查看>>
centos 脚本基础练习9
查看>>
我的友情链接
查看>>
GET和POST,有什么区别
查看>>
Android内存优化
查看>>
windows 安全策略
查看>>
centos6.9实现网卡bonding
查看>>