本题为LeetCode中第206道题(不是很难,只要数据结构基础可以就行)
反转一个单链表。
示例:
1 | 输入: 1->2->3->4->5->NULL |
进阶:
你可以迭代或递归地反转链表。你能否用两种方法解决这道题?
博主代码如下:
1 | /** |
今天就不再看别的代码了,因为博主的提交意见战胜了100%的提交,所以不看别的了
不过我可以说另外一种思路,凡是这种有关让你倒转的题,都可以使用栈来做,栈的特性先进后出
本题为LeetCode中第206道题(不是很难,只要数据结构基础可以就行)
反转一个单链表。
示例:
1 | 输入: 1->2->3->4->5->NULL |
进阶:
你可以迭代或递归地反转链表。你能否用两种方法解决这道题?
博主代码如下:
1 | /** |
今天就不再看别的代码了,因为博主的提交意见战胜了100%的提交,所以不看别的了
不过我可以说另外一种思路,凡是这种有关让你倒转的题,都可以使用栈来做,栈的特性先进后出