1261. 在受污染的二叉树中查找元素
class FindElements(object):
# treeNode.left.val == 2 * x + 1
# treeNode.right.val == 2 * x + 2
def __init__(self, root):
"""
:type root: TreeNode
"""
self.mylict = []
self.recover(root, 0)
def recover(self, root, flag):
if flag == 0:
root.val = 0
flag = 1
self.mylict.append(root.val)
if root.left:
root.left.val = 2 * root.val + 1
self.recover(root.left, flag)
if root.right:
root.right.val = 2 * root.val + 2
self.recover(root.right, flag)
def find(self, target):
"""
:type target: int
:rtype: bool
"""
print(self.mylict)
if target in self.mylict:
return True
else:
return False