auto commit
This commit is contained in:
parent
945f08197d
commit
3b13fdfa73
@ -243,18 +243,14 @@ public ArrayList<Integer> printListFromTailToHead(ListNode listNode) {
|
||||
|
||||
根据二叉树的前序遍历和中序遍历的结果,重建出该二叉树。假设输入的前序遍历和中序遍历的结果中都不含重复的数字。
|
||||
|
||||
```html
|
||||
preorder = [3,9,20,15,7]
|
||||
inorder = [9,3,15,20,7]
|
||||
```
|
||||
|
||||
<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/_u91CD_u5EFA_u4E8C_u53C9_u6811-1.gif" width="200"/> </div><br>
|
||||
<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/31d9adce-2af8-4754-8386-0aabb4e500b0.png" width="300"/> </div><br>
|
||||
|
||||
## 解题思路
|
||||
|
||||
前序遍历的第一个值为根节点的值,使用这个值将中序遍历结果分成两部分,左部分为树的左子树中序遍历结果,右部分为树的右子树中序遍历的结果。
|
||||
|
||||
<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/_u91CD_u5EFA_u4E8C_u53C9_u6811-21548502782193.gif"/> </div><br>
|
||||
<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/c269e362-1128-4212-9cf3-d4c12b363b2f.gif" width="330px"> </div><br>
|
||||
|
||||
```java
|
||||
// 缓存中序遍历数组每个值对应的索引
|
||||
|
BIN
docs/pics/31d9adce-2af8-4754-8386-0aabb4e500b0.png
Normal file
BIN
docs/pics/31d9adce-2af8-4754-8386-0aabb4e500b0.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 30 KiB |
BIN
docs/pics/c269e362-1128-4212-9cf3-d4c12b363b2f.gif
Normal file
BIN
docs/pics/c269e362-1128-4212-9cf3-d4c12b363b2f.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 40 KiB |
BIN
notes/pics/31d9adce-2af8-4754-8386-0aabb4e500b0.png
Normal file
BIN
notes/pics/31d9adce-2af8-4754-8386-0aabb4e500b0.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 30 KiB |
BIN
notes/pics/c269e362-1128-4212-9cf3-d4c12b363b2f.gif
Normal file
BIN
notes/pics/c269e362-1128-4212-9cf3-d4c12b363b2f.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 40 KiB |
@ -243,18 +243,14 @@ public ArrayList<Integer> printListFromTailToHead(ListNode listNode) {
|
||||
|
||||
根据二叉树的前序遍历和中序遍历的结果,重建出该二叉树。假设输入的前序遍历和中序遍历的结果中都不含重复的数字。
|
||||
|
||||
```html
|
||||
preorder = [3,9,20,15,7]
|
||||
inorder = [9,3,15,20,7]
|
||||
```
|
||||
|
||||
<div align="center"> <img src="pics/_u91CD_u5EFA_u4E8C_u53C9_u6811-1.gif" width="200"/> </div><br>
|
||||
<div align="center"> <img src="pics/31d9adce-2af8-4754-8386-0aabb4e500b0.png" width="300"/> </div><br>
|
||||
|
||||
## 解题思路
|
||||
|
||||
前序遍历的第一个值为根节点的值,使用这个值将中序遍历结果分成两部分,左部分为树的左子树中序遍历结果,右部分为树的右子树中序遍历的结果。
|
||||
|
||||
<div align="center"> <img src="pics/_u91CD_u5EFA_u4E8C_u53C9_u6811-21548502782193.gif"/> </div><br>
|
||||
<div align="center"> <img src="pics/c269e362-1128-4212-9cf3-d4c12b363b2f.gif" width="330px"> </div><br>
|
||||
|
||||
```java
|
||||
// 缓存中序遍历数组每个值对应的索引
|
||||
|
Loading…
x
Reference in New Issue
Block a user