Skip to content

Commit 7a021a3

Browse files
author
Partho Biswas
committed
no message
1 parent 9bc4219 commit 7a021a3

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,7 @@ Check this [golden](https://tinyurl.com/ujopecz) post.
431431
|11| **[729. My Calendar I](https://tinyurl.com/r3ew2lb)** | [Python](https://tinyurl.com/wu6rdaw/729_My_Calendar_I.py), [Swift](https://tinyurl.com/wuja3c4/729_My_Calendar_I.swift)| [Art 1](https://tinyurl.com/tbd2z7u), [Art 2](https://tinyurl.com/t35fp3e) | Medium | Use self balancing BST for O(nlogn) solution. **Very important** |
432432
|12| **[449. Serialize and Deserialize BST](https://tinyurl.com/rx9rn3l)** | [Python](https://tinyurl.com/wu6rdaw/449_Serialize_and_Deserialize_BST.py), [Swift](https://tinyurl.com/wuja3c4/449_Serialize_and_Deserialize_BST.swift)| [Art 1](https://tinyurl.com/t6e2b97) | Medium | --- |
433433
|13| **[1008. Construct Binary Search Tree from Preorder Traversal](https://tinyurl.com/y6less2m)** | [Python](https://tinyurl.com/wu6rdaw/1008_Construct_Binary_Search_Tree_from_Preorder_Traversal.py), [Swift](https://tinyurl.com/wuja3c4/1008_Construct_Binary_Search_Tree_from_Preorder_Traversal.swift)| [Art 1](https://tinyurl.com/y9mondek), [Art 2](https://tinyurl.com/y8byt732), [Art 3](https://tinyurl.com/yaq7w2jt), [Art 4](https://tinyurl.com/ybwtzpzo) | Medium | --- |
434+
|14| **[653. Two Sum IV - Input is a BST](https://tinyurl.com/ydzdnawg)** | [Python](https://tinyurl.com/wu6rdaw/653_Two_Sum_IV_Input_is_a_BST.py), [Swift](https://tinyurl.com/wuja3c4/653_Two_Sum_IV_Input_is_a_BST.swift)| - | Easy | --- |
434435

435436
</p>
436437
</details>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Definition for a binary tree node.
2+
# class TreeNode(object):
3+
# def __init__(self, val=0, left=None, right=None):
4+
# self.val = val
5+
# self.left = left
6+
# self.right = right
7+
class Solution(object):
8+
def findTarget(self, root, k):
9+
"""
10+
:type root: TreeNode
11+
:type k: int
12+
:rtype: bool
13+
"""
14+
diffSet = set()
15+
return self.findTargetHelper(root, k, diffSet)
16+
17+
def findTargetHelper(self, root, k, diffSet):
18+
if not root:
19+
return False
20+
if root.val in diffSet:
21+
return True
22+
else:
23+
diffSet.add((k - root.val))
24+
left = self.findTargetHelper(root.left, k, diffSet)
25+
right = self.findTargetHelper(root.right, k, diffSet)
26+
return left or right

0 commit comments

Comments
 (0)