Easy Python Solution | Faster than 99% (76 ms) | Comments
Easy Python Solution | Faster than 99% (76 ms) | With Comments\n\nRuntime: 76 ms, faster than 99.13% of Python3 online submissions for Find Elements in a Contam
# Easy Python Solution | Faster than 99% (76 ms) | With Comments\n\n**Runtime: 76 ms, faster than 99.13% of Python3 online submissions for Find Elements in a Contaminated Binary Tree.\nMemory Usage: 17.9 MB**\n\n```\nclass FindElements:\n    \n    def dfs(self, node, val):\n        if node:\n            self.store[val] = 1  # adding the value of node to hashmap\n            if node.left:\n                vl = (2 * val) + 1  # correcting the value of left node\n                self.dfs(node.left,vl)  # left sub tree traversal\n            if node.right:\n                vr = (2* val) + 2  # correcting the value of right node\n                self.dfs(node.right, vr)  # right sub tree traversal\n\n    def __init__(self, root: TreeNode):\n        self.store = {}  # hashmap for storing the corrected node values. And searching the values.\n        self.dfs(root, 0)  # Traversing the incorrect tree and saving correct values on the way\n\n    def find(self, target: int) -> bool:\n\t\t# checking if the target value exists in O(1) time\n        if self.store.get(target, None) is not None:\n            return True\n        else:\n            return False\n```\n![image](https://assets.leetcode.com/users/images/378c2109-1b90-48a2-829e-fab65cc6abbc_1652190280.408396.png)\n\n
['Depth-First Search', 'Recursion', 'Python', 'Python3']