2019年3月4日 701. Insert into a Binary Search Tree
生活随笔
收集整理的這篇文章主要介紹了
2019年3月4日 701. Insert into a Binary Search Tree
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
比較基礎(chǔ)的二叉樹排序樹插入,寫了個(gè)遞歸。
# Definition for a binary tree node. # class TreeNode(object): # def __init__(self, x): # self.val = x # self.left = None # self.right = Noneclass Solution(object):def insertIntoBST(self, root, val):""":type root: TreeNode:type val: int:rtype: TreeNode"""if root is None:return TreeNode(val)if val < root.val:root.left = self.insertIntoBST(root.left, val)else:root.right = self.insertIntoBST(root.right, val)return root轉(zhuǎn)載于:https://www.cnblogs.com/seenthewind/p/10469322.html
總結(jié)
以上是生活随笔為你收集整理的2019年3月4日 701. Insert into a Binary Search Tree的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: android手机如何安装apk文件,如
- 下一篇: 华为 鸿蒙 升级,华为鸿蒙系统已陆续推送