leetcode558
"""
# Definition for a QuadTree node.
class Node(object):
def __init__(self, val, isLeaf, topLeft, topRight, bottomLeft, bottomRight):
self.val = val
self.isLeaf = isLeaf
self.topLeft = topLeft
self.topRight = topRight
self.bottomLeft = bottomLeft
self.bottomRight = bottomRight
"""
class Solution(object):
def intersect(self, q1, q2):
"""
:type q1: Node
:type q2: Node
:rtype: Node
"""
if q1.isLeaf:
return q1 if q1.val else q2
if q2.isLeaf:
return q2 if q2.val else q1 q1.topLeft = self.intersect(q1.topLeft, q2.topLeft)
q1.topRight = self.intersect(q1.topRight, q2.topRight)
q1.bottomLeft = self.intersect(q1.bottomLeft, q2.bottomLeft)
q1.bottomRight = self.intersect(q1.bottomRight, q2.bottomRight) if q1.topLeft.isLeaf and q1.topRight.isLeaf and q1.bottomLeft.isLeaf and q1.bottomRight.isLeaf:
if q1.topLeft.val == q1.topRight.val == q1.bottomLeft.val == q1.bottomRight.val:
q1.isLeaf = True
q1.val = q1.topLeft.val
return q1
从网上寻找的代码。
leetcode558的更多相关文章
随机推荐
- Linux服务器运行环境搭建(二)——Redis数据库安装
官网地址:http://redis.io/ 官网下载地址:http://redis.io/download 1. 下载Redis源码(tar.gz),并上传到Linux 2. 解压缩包:tar zxv ...
- Linux运行环境搭建(一)——安装JDK
下载Linux版jdk 官网:http://www.oracle.com/technetwork/java/javase/downloads/index.html 解压并拷贝到指定目录 tar zxv ...
- js里获取html真实舞台宽高
var winSize = {width:document.documentElement.clientWidth,height:document.documentElement.clientHeig ...
- BZOJ3325 [Scoi2013]密码【Manacher】【构造】【贪心】
Description Fish是一条生活在海里的鱼.有一天他很无聊,就到处去寻宝.他找到了位于海底深处的宫殿,但是一扇带有密码锁的大门却阻止了他的前进.通过翻阅古籍,Fish 得知了这个密码的相关信 ...
- CALayer4-自定义层
一.自定义层的方法1 方法描述:创建一个CALayer的子类,然后覆盖drawInContext:方法,使用Quartz2D API进行绘图 1.创建一个CALayer的子类 2.在.m文件中覆盖dr ...
- 《DSP using MATLAB》示例Example 6.28
代码: % The following 3 lines produce filter coefficients shown in Table 6.1 wp = [0.35, 0.65]; ws = [ ...
- 通过 Windows API 获取鼠标位置等状态信息
#include <graphics.h> #include <stdio.h> void main() { initgraph(, ); // 初始化绘图窗口 HWND hw ...
- 数据库视图View的使用
一.视图的概念: 概念: 视图是指计算机数据库中的视图,是一个虚拟表,其内容由查询定义.同真实的表一样,视图包含一系列带有名称的列和行数据.但是,视图并不在数据库中以存储的数据值集形式存在.行和列数据 ...
- MYSQL子查询例题以及答案
More Subqueries Quizzes Above is the ERD for the database again - it might come in handy as you tack ...
- 洛谷1527(bzoj2738)矩阵乘法——二维树状数组+整体二分
题目:https://www.luogu.org/problemnew/show/P1527 不难想到(?)可以用二维树状数组.但维护什么?怎么查询是难点. 因为求第k小,可以考虑记权值树状数组,把比 ...