本题不会做,从网上找到了python3的解法,记录如下。

class Solution:
def construct(self, grid):
def dfs(x, y, l):
if l == 1:
node = Node(grid[x][y] == 1, True, None, None, None, None)
else:
tLeft = dfs(x, y, l // 2)
tRight = dfs(x, y + l // 2, l // 2)
bLeft = dfs(x + l // 2, y, l// 2)
bRight = dfs(x + l // 2, y + l // 2, l // 2)
value = tLeft.val or tRight.val or bLeft.val or bRight.val
if tLeft.isLeaf and tRight.isLeaf and bLeft.isLeaf and bRight.isLeaf and tLeft.val == tRight.val == bLeft.val == bRight.val:
node = Node(value, True, None, None, None, None)
else:
node = Node(value, False, tLeft, tRight, bLeft, bRight)
return node
return grid and dfs(0, 0, len(grid)) or None

最新文章

  1. SMARTFORM & SAPScript
  2. 使用delegate实现简单的查询功能
  3. Python Paramiko模块与MySQL数据库操作
  4. linux下动态库编译的依赖问题
  5. js带缩略图的图片切换效果
  6. linux 入侵检查转载
  7. linux-3.0下input_dev模型按键驱动
  8. Activity进入与退出的动画
  9. vs2017添加引用时报错未能正确加载“ReferenceManagerPackage”包。
  10. Android 7.0 Power 按键处理流程
  11. MySQL 高性能优化实战总结
  12. ElasticSearch5.5.1插件分类
  13. Spring/SpringBoot定义统一异常错误码返回
  14. Soa思想分布式服务webservice WCF
  15. php+xml有什么用
  16. 【原创】Qt 使用ODBC driver 连接SQL Server
  17. python基础知识-12-模块的了解
  18. 100baseT、100baseFX、1000base-SX、100/1000base-T
  19. 【转】Java面试题全集(上)
  20. 20145233《网络对抗》Exp7 DNS网络欺诈技术防范

热门文章

  1. JSP的指令
  2. Thrift之c++实例
  3. Tomcat Jsp环境搭建全过程--重拾jsp
  4. 使用Kali Linux执行中间人攻击(演示)
  5. C# 在类文件自动添加文件注释的方法
  6. 关于使用modelsim的一点感想
  7. ACM学习历程—计蒜客15 单独的数字(位运算)
  8. LA4992 Jungle Post
  9. Spring IOC容器在Web容器中是怎样启动的
  10. 十五、python沉淀之路--eval()的用法