摘要: 本次使用的递归思想是非常基础且重要的。思路就是首先从数组的中间位置建立跟节点,然后元素左边的递归建立左子树,元素右边递归建立右子树。 1 class Solution: 2 def sortedArrayToBST(self, nums: List[int]) -> TreeNode: 3 if n 阅读全文
posted @ 2020-09-16 14:51 lzk_seven 阅读(231) 评论(0) 推荐(0) 编辑
摘要: leetcode 226翻转二叉树(剑指offer.二叉树的镜像) 初级递归 1 class Solution: 2 def invertTree(self, root: TreeNode) -> TreeNode: 3 if not root: 4 return 5 root.left,root. 阅读全文
posted @ 2020-09-16 14:39 lzk_seven 阅读(353) 评论(0) 推荐(0) 编辑