class Solution:
def insertIntoBST(self, root: TreeNode, val: int) -> TreeNode:
if root == None:
return TreeNode(val)
if root.val == val: #该节点已存在,则不插入
return root
elif val < root.val: #若插入值小于当前节点,递归处理左节点
root.left = self.insertIntoBST(root.left, val)
elif val > root.val: #若插入值大于当前节点,递归处理左右节点
root.right = self.insertIntoBST(root.right, val)
return root #注意return当前root