zoukankan      html  css  js  c++  java
  • 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

    从网上寻找的代码。

  • 相关阅读:
    json
    网页版 treeview使用中遇到的问题
    随机获取一条数据
    oracle
    发送邮件
    DataGrid列的合并
    python简介
    SQLSERVER
    Maven 基础
    Maven 构建jar包
  • 原文地址:https://www.cnblogs.com/asenyang/p/9734904.html
Copyright © 2011-2022 走看看