Skip to content

Latest commit

 

History

History
25 lines (13 loc) · 514 Bytes

reverse-linked-list.md

File metadata and controls

25 lines (13 loc) · 514 Bytes

Reverse Linked List

描述

Reverse a singly linked list.

分析

用三个指针 tail,p,q,紧紧相邻,不断前进,每次将p.next指向tail,将q.next指向p

解法1 迭代

{% if book.java %} {% codesnippet "./code/reverse-linked-list-1."+book.suffix, language=book.suffix %}{% endcodesnippet %} {% endif %}

解法2 递归

{% if book.java %} {% codesnippet "./code/reverse-linked-list-2."+book.suffix, language=book.suffix %}{% endcodesnippet %} {% endif %}