Skip to content

Added Python Solution LC Problem No.0653 in README.md, README_EM.md, Solution.py #530

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jul 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion solution/0600-0699/0653.Two Sum IV - Input is a BST/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,24 @@ 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:
def find(node):
if not node:
return False
if k - node.val in nodes:
return True
nodes.add(node.val)
return find(node.left) or find(node.right)

nodes = set()
return find(root)
```

### **Java**
Expand Down
19 changes: 18 additions & 1 deletion solution/0600-0699/0653.Two Sum IV - Input is a BST/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,24 @@
### **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:
def find(node):
if not node:
return False
if k - node.val in nodes:
return True
nodes.add(node.val)
return find(node.left) or find(node.right)

nodes = set()
return find(root)
```

### **Java**
Expand Down
18 changes: 18 additions & 0 deletions solution/0600-0699/0653.Two Sum IV - Input is a BST/Solution.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# 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:
def find(node):
if not node:
return False
if k - node.val in nodes:
return True
nodes.add(node.val)
return find(node.left) or find(node.right)

nodes = set()
return find(root)