Skip to content

Commit 24964c1

Browse files
authored
Create 0701-insert-into-a-binary-search-tree.py
1 parent 8f7febc commit 24964c1

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Definition for a binary tree node.
2+
# class TreeNode:
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:
8+
def insertIntoBST(self, root: Optional[TreeNode], val: int) -> Optional[TreeNode]:
9+
if not root:
10+
return TreeNode(val)
11+
if val > root.val:
12+
root.right = self.insertIntoBST(root.right, val)
13+
else:
14+
root.left = self.insertIntoBST(root.left, val)
15+
return root

0 commit comments

Comments
 (0)