Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 03e8853

Browse files
docs: add a description of the solution (doocs#659)
1 parent c0cb11c commit 03e8853

File tree

1 file changed

+12
-1
lines changed
  • lcof/面试题06. 从尾到头打印链表

1 file changed

+12
-1
lines changed

‎lcof/面试题06. 从尾到头打印链表/README.md‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,18 @@
1717

1818
## 解法
1919

20-
栈实现。或者其它方式,见题解。
20+
该题需要将链表转换为数组,且需要反向。由于目标是链表,无法第一时间得知长度,声明等长数组。
21+
22+
解题方案:
23+
- 遍历
24+
- 从头到尾遍链表,获取链表长度,声明等长数组;
25+
- 再次遍历并放入数组当中,在数组中的放置顺序是从尾到头。
26+
- 递归
27+
- 记录深度,递归到链表尾部;
28+
- 将深度化为数组长度,将回溯结果正序放入数组当中。
29+
- 动态数组
30+
- 遍历链表,将元素放入数组当中;
31+
- 遍历结束,将数组倒置后返回(`reverse()`)。
2132

2233
<!-- tabs:start -->
2334

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /