Leetcode 701. Insert into a Binary Search Tree
Posted 周洋的Blog
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Leetcode 701. Insert into a Binary Search Tree相关的知识,希望对你有一定的参考价值。
import functools @functools.lru_cache() class Solution(object): def insertIntoBST(self, root, val): """ :type root: TreeNode :type val: int :rtype: TreeNode """ if not root: return if val > root.val: if not root.right: root.right = TreeNode(val) else: self.insertIntoBST(root.right, val) else: if not root.left: root.left = TreeNode(val) else: self.insertIntoBST(root.left, val) return root
以上是关于Leetcode 701. Insert into a Binary Search Tree的主要内容,如果未能解决你的问题,请参考以下文章
[LeetCode] 701. Insert into a Binary Search Tree
leetcode701. Insert into a Binary Search Tree
Leetcode 701. Insert into a Binary Search Tree
701. Insert into a Binary Search Tree