Skip to content

Commit 700f7dd

Browse files
committed
在二叉查找树中插入节点
1 parent bb25c4b commit 700f7dd

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# -*- coding: utf-8 -*-
2+
3+
class Solution:
4+
"""
5+
@param root: The root of the binary search tree.
6+
@param node: insert this node into the binary search tree.
7+
@return: The root of the new binary search tree.
8+
"""
9+
def insertNode(self, root, node):
10+
# write your code here
11+
if root is None:
12+
return node
13+
if root.val > node.val:
14+
root.left = self.insertNode(root.left, node)
15+
else:
16+
root.right = self.insertNode(root.right, node)
17+
return root

0 commit comments

Comments
 (0)