701. 二叉搜索树中的插入操作(Medium)
class Solution:
def insertIntoBST(self, root: TreeNode, val: int) -> TreeNode:
def search(root, val):
if not root: return TreeNode(val)
if val > root.val:
root.right = search(root.right, val)
else:
root.left = search(root.left, val)
return root
return search(root, val)