leetcode427
本题不会做,从网上找到了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
leetcode427的更多相关文章
随机推荐
- Node.js小白开路(一)-- console篇
在所有内容的学习之中我们经常首先要接受到的常常很大一部分为命令行或是工具的内容展示,console内容为node.js在命令行中答应数据内容的一个途径. Console是nodejs中的元老级模块了. ...
- List排序共通代码
此共通方法可以根据特定字段进行排序 package com.gomecar.index.common.utils; import java.lang.reflect.Method; import ja ...
- Android event logcat的研究
经常有这样的需求:在程序A启动之后,在这个程序上覆盖一个界面,让用户输入密码后才能启动程序A,这类场景主要集中在安全软件中. 那应该怎样得知某某程序启动了,系统没有相应的广播,这很难知道程序启动了. ...
- Electron 使用 Webpack2 预编译 Electron 和 Browser targets
Electron 使用 Webpack2 预编译 Electron 和 Browser targets 前一篇文章说了说怎样使用 Webpack2 预编译 Electron 应用,但是有时候我们希望使 ...
- OpenCV中阈值(threshold)函数: threshold 。
OpenCV中提供了阈值(threshold)函数: threshold . 这个函数有5种阈值化类型,在接下来的章节中将会具体介绍. 为了解释阈值分割的过程,我们来看一个简单有关像素灰度的图片,该图 ...
- 自己搭建MVC时遇到的一些问题及解决办法
错误1 The view 'Index' or its master was not found or no view engine supports the searched locations. ...
- uid
var uid = 0 function nextUid() { return ++uid }
- Sublimetext3的下载与安装
https://www.sublimetext.com/ Sublimetext价格不菲,但是作者允许无限期的免费试用,请不要下载破解版 使用国内汉化版的很有可能感染病毒,请善待电脑 百度搜索找到官网 ...
- W3Schools SQL Quiz
W3Schools SQL Quiz SQL QUIZ Points: 25 out of 25 1. What does SQL stand for? You answered: Structure ...
- VC++ windows开机自启动设置
设置开机启动 很多软件要求软件能够在开机时自启动,下面讲讲如何设置开机自启动. Windows设置程序的开机启动的方法有很多,这里只讲其中的一种,该方法同时适用于32位和64位的操作系统,只需将需要开 ...