python - twosome

  • 0
    # Definition for a binary tree node.
    # class TreeNode(object):
    #     def __init__(self, x):
    #         self.val = x
    #         self.left = None
    #         self.right = None
    class Solution(object):
        def findTarget(self, root, k):
            :type root: TreeNode
            :type k: int
            :rtype: bool
            if root:
                queue, cache = [root], set()
                for node in queue:
                    if node.val in cache: return True
                    if node.left:  queue.append(node.left)
                    if node.right: queue.append(node.right)
            return False

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.