From 2f86a5ce27078eff58b5d6e2765091ed01f04d94 Mon Sep 17 00:00:00 2001 From: jianghongcheng <35664721+jianghongcheng@users.noreply.github.com> Date: Wed, 24 May 2023 22:39:35 -0500 Subject: [PATCH] =?UTF-8?q?Update=200701.=E4=BA=8C=E5=8F=89=E6=90=9C?= =?UTF-8?q?=E7=B4=A2=E6=A0=91=E4=B8=AD=E7=9A=84=E6=8F=92=E5=85=A5=E6=93=8D?= =?UTF-8?q?=E4=BD=9C.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../0701.二叉搜索树中的插入操作.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/problems/0701.二叉搜索树中的插入操作.md b/problems/0701.二叉搜索树中的插入操作.md index 1ba7461f..fc4351ba 100644 --- a/problems/0701.二叉搜索树中的插入操作.md +++ b/problems/0701.二叉搜索树中的插入操作.md @@ -326,7 +326,22 @@ class Solution: return root ``` +递归法(版本四) +```python +class Solution: + def insertIntoBST(self, root, val): + if root is None: + node = TreeNode(val) + return node + if root.val > val: + root.left = self.insertIntoBST(root.left, val) + if root.val < val: + root.right = self.insertIntoBST(root.right, val) + + return root + +``` 迭代法 ```python