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的更多相关文章
随机推荐
- 使用python处理selenium中的获取文本问题
# 获取文本 button_name = self.driver.find_element_by_id("sign_in_display").text
- 让一个 csproj 项目指定多个开发框架
可移植类库.共享项目..NET Standard 项目都能够帮我们完成跨多个 .NET SDK 的单一项目开发,但它们的跨 SDK 开发都有些限制.现在,我们又有新的方式能够跨多个 .NET SDK ...
- Tornado之实例和扩展
1.Tornado文件的结构: 1.Controllers控制器 2.Models数据库操作 3.Views前端显示 2.样例 #!/usr/bin/env python # -*- coding: ...
- ballerina 学习九 Client endpoints
说白了就是连接外部服务的,可以是http jms websocket .... 简单例子 代码 import ballerina/http; import ballerina/log; endpoin ...
- warning: backslash and newline separated by space [enabled by default]
警告:反斜杠和换行符之间多了空格. 这种问题出现在宏定义 #define,并且有多行,每行之间要用 “\” 连接起来. 解决办法:删除 “\” 后面的空格,直接紧跟回车.
- nginx学习与配置-安装与启动关闭管理
nginx服务器的安装 安装准备: nginx依赖于pcre库,要先安装pcre yum install pcre pcre-devel cd /usr/local/src/ wget wget ht ...
- Unit04: 实战技巧 、 登录
Unit04: 实战技巧 . 登录 使用注解方式简化Unit04的小程序. 1. 基于注解的springmvc应用程序的开发 (1)编程步骤 step1. 导包. step2. 添加spring配置文 ...
- AT 指令和常见错误码
一. 一般命令 1. AT+CGMI 给出模块厂商的标识. 2. AT+CGMM 获得模块标识.这个命令用来得到支持的频带(GSM 900,DCS 1800 或PCS 1900).当模块有多频带时,回 ...
- cocos2d-js 3.0 ios平台编译打包
原帖在http://www.cocoachina.com/bbs/read.php?tid=209356 整理到github的https://github.com/faint2death/cocos2 ...
- Java web 第一天
java web 的开发一般都是采用比较经典的分层结构: MVC(Model-View-Control)结构,在MVC 结构中,Model层用于处理业务相关,View层用于处理显示相关(View一般为 ...