auto commit
BIN
docs/notes/pics/_u4ECE_u5C3E_u5230_u5934_u6253_1548293773431.gif
Normal file
After Width: | Height: | Size: 16 KiB |
BIN
docs/notes/pics/_u4ECE_u5C3E_u5230_u5934_u6253_1548293972480.gif
Normal file
After Width: | Height: | Size: 6.0 KiB |
BIN
docs/notes/pics/_u4ECE_u5C3E_u5230_u5934_u6253_1548294571338.gif
Normal file
After Width: | Height: | Size: 17 KiB |
BIN
docs/notes/pics/_u4ECE_u5C3E_u5230_u5934_u6253_1548295232667.gif
Normal file
After Width: | Height: | Size: 16 KiB |
|
@ -246,12 +246,14 @@ public String replaceSpace(StringBuffer str) {
|
|||
|
||||
从尾到头反过来打印出每个结点的值。
|
||||
|
||||
<div align="center"> <img src="pics/d99dc9e2-197c-4085-813d-7195da1c6762.png" width="300"/> </div><br>
|
||||
<div align="center"> <img src="pics/_u4ECE_u5C3E_u5230_u5934_u6253_1548293972480.gif" width="250px"> </div><br>
|
||||
|
||||
## 解题思路
|
||||
|
||||
### 使用栈
|
||||
|
||||
<div align="center"> <img src="pics/_u4ECE_u5C3E_u5230_u5934_u6253_1548293773431.gif" width="500px"> </div><br>
|
||||
|
||||
```java
|
||||
public ArrayList<Integer> printListFromTailToHead(ListNode listNode) {
|
||||
Stack<Integer> stack = new Stack<>();
|
||||
|
@ -268,6 +270,8 @@ public ArrayList<Integer> printListFromTailToHead(ListNode listNode) {
|
|||
|
||||
### 使用递归
|
||||
|
||||
<div align="center"> <img src="pics/_u4ECE_u5C3E_u5230_u5934_u6253_1548294571338.gif" width="200px"> </div><br>
|
||||
|
||||
```java
|
||||
public ArrayList<Integer> printListFromTailToHead(ListNode listNode) {
|
||||
ArrayList<Integer> ret = new ArrayList<>();
|
||||
|
@ -288,6 +292,8 @@ public ArrayList<Integer> printListFromTailToHead(ListNode listNode) {
|
|||
- 头结点是在头插法中使用的一个额外节点,这个节点不存储值;
|
||||
- 第一个节点就是链表的第一个真正存储值的节点。
|
||||
|
||||
<div align="center"> <img src="pics/_u4ECE_u5C3E_u5230_u5934_u6253_1548295232667.gif"/> </div><br>
|
||||
|
||||
```java
|
||||
public ArrayList<Integer> printListFromTailToHead(ListNode listNode) {
|
||||
// 头插法构建逆序链表
|
||||
|
@ -309,20 +315,6 @@ public ArrayList<Integer> printListFromTailToHead(ListNode listNode) {
|
|||
}
|
||||
```
|
||||
|
||||
### 使用 Collections.reverse()
|
||||
|
||||
```java
|
||||
public ArrayList<Integer> printListFromTailToHead(ListNode listNode) {
|
||||
ArrayList<Integer> ret = new ArrayList<>();
|
||||
while (listNode != null) {
|
||||
ret.add(listNode.val);
|
||||
listNode = listNode.next;
|
||||
}
|
||||
Collections.reverse(ret);
|
||||
return ret;
|
||||
}
|
||||
```
|
||||
|
||||
# 7. 重建二叉树
|
||||
|
||||
[NowCoder](https://www.nowcoder.com/practice/8a19cbe657394eeaac2f6ea9b0f6fcf6?tpId=13&tqId=11157&tPage=1&rp=1&ru=/ta/coding-interviews&qru=/ta/coding-interviews/question-ranking)
|
||||
|
|
BIN
docs/pics/_u4ECE_u5C3E_u5230_u5934_u6253_1548293773431.gif
Normal file
After Width: | Height: | Size: 16 KiB |
BIN
docs/pics/_u4ECE_u5C3E_u5230_u5934_u6253_1548293972480.gif
Normal file
After Width: | Height: | Size: 6.0 KiB |
BIN
docs/pics/_u4ECE_u5C3E_u5230_u5934_u6253_1548294571338.gif
Normal file
After Width: | Height: | Size: 17 KiB |
BIN
docs/pics/_u4ECE_u5C3E_u5230_u5934_u6253_1548295232667.gif
Normal file
After Width: | Height: | Size: 16 KiB |