Esempio n. 1
0
def create_example():
    root = TreeNode(4)
    two = TreeNode(2)
    sev = TreeNode(7)
    one = TreeNode(1)
    thr = TreeNode(3)
    six = TreeNode(6)
    nin = TreeNode(9)

    root.left = two
    root.right = sev
    two.left = one
    two.right = thr
    sev.left = six
    sev.right = nin
    return root
                return False
            qL += curL.left,
            qL += curL.right,    
            qR += curR.right,
            qR += curR.left,
            
        return True

if __name__ == "__main__":
    from data_structures.TreeNode import TreeNode
    
    threeL = TreeNode(3)
    threeR = TreeNode(3)
    fourL = TreeNode(4)
    fourR = TreeNode(4)
    twoL = TreeNode(2)
    twoR = TreeNode(2)
    root = TreeNode(1)

    root.left = twoL
    root.right = twoR
    twoL.left = threeL
    twoR.right = threeR
    twoL.right = fourR
    twoR.left = fourL
    
    S = Solution()
    print S.isSymmetric(root) #example from comments above
    
    twoR.right, twoR.left = twoR.left, twoR.right #swap two nodes and...
    print S.isSymmetric(root) #as is above
def create_example():
    root = TreeNode(4)
    two = TreeNode(2)
    sev = TreeNode(7)
    one = TreeNode(1)
    thr = TreeNode(3)
    six = TreeNode(6)
    nin = TreeNode(9)

    root.left = two
    root.right = sev
    two.left = one
    two.right = thr
    sev.left = six
    sev.right = nin
    return root
Esempio n. 4
0
            elif curR is None or curL is None:
                return False
            if curL.val != curR.val:
                return False
            qL += curL.left,
            qL += curL.right,
            qR += curR.right,
            qR += curR.left,

        return True


if __name__ == "__main__":
    from data_structures.TreeNode import TreeNode

    threeL = TreeNode(3)
    threeR = TreeNode(3)
    fourL = TreeNode(4)
    fourR = TreeNode(4)
    twoL = TreeNode(2)
    twoR = TreeNode(2)
    root = TreeNode(1)

    root.left = twoL
    root.right = twoR
    twoL.left = threeL
    twoR.right = threeR
    twoL.right = fourR
    twoR.left = fourL

    S = Solution()