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
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
            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
Esempio n. 4
0
            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