Skip to content

Instantly share code, notes, and snippets.

@cixuuz
Created August 6, 2017 02:30
Show Gist options
  • Save cixuuz/0a13a532c7e834e0bc98b9d401bc5a75 to your computer and use it in GitHub Desktop.
Save cixuuz/0a13a532c7e834e0bc98b9d401bc5a75 to your computer and use it in GitHub Desktop.
[653. Two Sum IV - Input is a BST] #leetcode
class Solution:
cor = set()
def findTarget(self, root, k):
"""
:type root: TreeNode
:type k: int
:rtype: bool
"""
if root is None:
return False
if root.val in self.cor:
return True
else:
self.cor.add(k - root.val)
return self.findTarget(root.left, k) or self.findTarget(root.right, k)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment