From 8668d724369650ed28be45709b964f43b7246f42 Mon Sep 17 00:00:00 2001 From: Ashwin Solanki Date: Wed, 21 Jul 2021 18:47:16 +0530 Subject: [PATCH 1/6] Added Python Solution to No.0653 in README.md --- .../0653.Two Sum IV - Input is a BST/README.md | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/solution/0600-0699/0653.Two Sum IV - Input is a BST/README.md b/solution/0600-0699/0653.Two Sum IV - Input is a BST/README.md index 8a130dda455ad..f41e9f03d62ca 100644 --- a/solution/0600-0699/0653.Two Sum IV - Input is a BST/README.md +++ b/solution/0600-0699/0653.Two Sum IV - Input is a BST/README.md @@ -54,7 +54,23 @@ Target = 28 ```python - +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, val=0, left=None, right=None): +# self.val = val +# self.left = left +# self.right = right +class Solution: + def findTarget(self, root: TreeNode, k: int) -> bool: + a=set() + def h(node): + if not node: + return False + if(k-node.val in a): + return True + a.add(node.val) + return h(node.right) or h(node.left) + return h(root) ``` ### **Java** From bb87d47ba8c9c93ac0c22d0472bd57c9a1d79b1b Mon Sep 17 00:00:00 2001 From: Ashwin Solanki Date: Wed, 21 Jul 2021 18:47:58 +0530 Subject: [PATCH 2/6] Added Python Solution to No.0653 in README_EN.md --- .../README_EN.md | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/solution/0600-0699/0653.Two Sum IV - Input is a BST/README_EN.md b/solution/0600-0699/0653.Two Sum IV - Input is a BST/README_EN.md index fe8bef93e2763..854baea36e297 100644 --- a/solution/0600-0699/0653.Two Sum IV - Input is a BST/README_EN.md +++ b/solution/0600-0699/0653.Two Sum IV - Input is a BST/README_EN.md @@ -60,7 +60,23 @@ ### **Python3** ```python - +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, val=0, left=None, right=None): +# self.val = val +# self.left = left +# self.right = right +class Solution: + def findTarget(self, root: TreeNode, k: int) -> bool: + a=set() + def h(node): + if not node: + return False + if(k-node.val in a): + return True + a.add(node.val) + return h(node.right) or h(node.left) + return h(root) ``` ### **Java** From 72d3092b3a6241bf1cfafd8bb9845074ed3d8beb Mon Sep 17 00:00:00 2001 From: Ashwin Solanki Date: Wed, 21 Jul 2021 18:48:56 +0530 Subject: [PATCH 3/6] feat: add Python solution to lc problems: No.0653 --- .../Solution.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 solution/0600-0699/0653.Two Sum IV - Input is a BST/Solution.py diff --git a/solution/0600-0699/0653.Two Sum IV - Input is a BST/Solution.py b/solution/0600-0699/0653.Two Sum IV - Input is a BST/Solution.py new file mode 100644 index 0000000000000..0800313e94137 --- /dev/null +++ b/solution/0600-0699/0653.Two Sum IV - Input is a BST/Solution.py @@ -0,0 +1,17 @@ +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, val=0, left=None, right=None): +# self.val = val +# self.left = left +# self.right = right +class Solution: + def findTarget(self, root: TreeNode, k: int) -> bool: + a=set() + def h(node): + if not node: + return False + if(k-node.val in a): + return True + a.add(node.val) + return h(node.right) or h(node.left) + return h(root) From 776aa3cd402cfaefdbbf36cec5e45ea324681a3a Mon Sep 17 00:00:00 2001 From: Yang Libin Date: Thu, 22 Jul 2021 09:23:00 +0800 Subject: [PATCH 4/6] Update Solution.py --- .../0653.Two Sum IV - Input is a BST/Solution.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/solution/0600-0699/0653.Two Sum IV - Input is a BST/Solution.py b/solution/0600-0699/0653.Two Sum IV - Input is a BST/Solution.py index 0800313e94137..755d0c574b412 100644 --- a/solution/0600-0699/0653.Two Sum IV - Input is a BST/Solution.py +++ b/solution/0600-0699/0653.Two Sum IV - Input is a BST/Solution.py @@ -6,12 +6,13 @@ # self.right = right class Solution: def findTarget(self, root: TreeNode, k: int) -> bool: - a=set() - def h(node): + def find(node): if not node: return False - if(k-node.val in a): + if k - node.val in nodes: return True - a.add(node.val) - return h(node.right) or h(node.left) - return h(root) + nodes.add(node.val) + return find(node.left) or find(node.right) + + nodes = set() + return find(root) From ead77990f2315d5961eee84cd24fe66fe5551381 Mon Sep 17 00:00:00 2001 From: Yang Libin Date: Thu, 22 Jul 2021 09:23:22 +0800 Subject: [PATCH 5/6] Update README_EN.md --- .../0653.Two Sum IV - Input is a BST/README_EN.md | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/solution/0600-0699/0653.Two Sum IV - Input is a BST/README_EN.md b/solution/0600-0699/0653.Two Sum IV - Input is a BST/README_EN.md index 854baea36e297..a2bb5f897dc9e 100644 --- a/solution/0600-0699/0653.Two Sum IV - Input is a BST/README_EN.md +++ b/solution/0600-0699/0653.Two Sum IV - Input is a BST/README_EN.md @@ -68,15 +68,16 @@ # self.right = right class Solution: def findTarget(self, root: TreeNode, k: int) -> bool: - a=set() - def h(node): + def find(node): if not node: return False - if(k-node.val in a): + if k - node.val in nodes: return True - a.add(node.val) - return h(node.right) or h(node.left) - return h(root) + nodes.add(node.val) + return find(node.left) or find(node.right) + + nodes = set() + return find(root) ``` ### **Java** From 6072108c4c90c26b248844df830fd3ddb67fd5cc Mon Sep 17 00:00:00 2001 From: Yang Libin Date: Thu, 22 Jul 2021 09:23:38 +0800 Subject: [PATCH 6/6] Update README.md --- .../0653.Two Sum IV - Input is a BST/README.md | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/solution/0600-0699/0653.Two Sum IV - Input is a BST/README.md b/solution/0600-0699/0653.Two Sum IV - Input is a BST/README.md index f41e9f03d62ca..b6bb412482e64 100644 --- a/solution/0600-0699/0653.Two Sum IV - Input is a BST/README.md +++ b/solution/0600-0699/0653.Two Sum IV - Input is a BST/README.md @@ -62,15 +62,16 @@ Target = 28 # self.right = right class Solution: def findTarget(self, root: TreeNode, k: int) -> bool: - a=set() - def h(node): + def find(node): if not node: return False - if(k-node.val in a): + if k - node.val in nodes: return True - a.add(node.val) - return h(node.right) or h(node.left) - return h(root) + nodes.add(node.val) + return find(node.left) or find(node.right) + + nodes = set() + return find(root) ``` ### **Java**