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