Skip to content

Commit 1b951c4

Browse files
authored
Update Day-23_Two Sum IV - Input is a BST.py
1 parent 6e3e427 commit 1b951c4

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

Leetcode_30day_challenge/August_Challenge_2021/Day-23_Two Sum IV - Input is a BST.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# TC: O(N) | SC: O(N)
2-
2+
# Method - 1: Traverse the BST, store the nodes values in a Dictionary. Then find the sum of two numbers equals target.
33
from collections import defaultdict
44
class Solution:
55
def findTarget(self, root: Optional[TreeNode], k: int) -> bool:
@@ -22,3 +22,5 @@ def inorder(root, d):
2222

2323
return False
2424

25+
# Method - 2: Since it is a BST, for every element we can search for the element b (b = target - node.val) in O(H) Time.
26+
# TC: O(N) and space will now be O(H) [Best: logN and Worst: N]

0 commit comments

Comments
 (0)