- 博客(4)
- 收藏
- 关注
原创 108. 将有序数组转换为二叉搜索树
https://leetcode-cn.com/problems/convert-sorted-array-to-binary-search-tree/description/ 思路:递归,根据有序的特性,每次取数组中点mid为根,递归构造左右子树# Definition for a binary tree node.# class TreeNode:# def __init__...
2018-09-13 17:54:05 221
原创 107. 二叉树的层次遍历 II
https://leetcode-cn.com/problems/binary-tree-level-order-traversal-ii/description/ 思路:层序遍历,然后结果倒序# Definition for a binary tree node.# class TreeNode:# def __init__(self, x):# self...
2018-09-13 17:50:42 206
原创 106. 从中序与后序遍历序列构造二叉树
https://leetcode-cn.com/problems/construct-binary-tree-from-inorder-and-postorder-traversal/description/ 思路:和105题类似,区别在于后序的-1号元素是中序的根,划分之后递归# Definition for a binary tree node.# class TreeNode:# ...
2018-09-13 17:49:03 126
原创 105. 从前序与中序遍历序列构造二叉树
https://leetcode-cn.com/problems/construct-binary-tree-from-preorder-and-inorder-traversal/description/思路:递归,易知前序的第0号元素为树的根,在中序里找这个根,然后以该根为界将中序数组划分成左右两半,依次递归进行。难点在于每次还要根据中序的划分来将前序数组也划分。# Definitio...
2018-09-13 17:47:15 166
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人