[LeetCode]206. Reverse Linked List
2017-05-06 00:23
337 查看
Reverseasinglylinkedlist.
clicktoshowmorehints.
Subscribetoseewhichcompaniesaskedthisquestion.
利用循环。
递归版
利用循环。
1publicclassSolution{ 2publicListNodereverseList(ListNodehead){ 3if(head==null||head.next==null)returnhead; 4ListNodepre=head; 5head=head.next; 6pre.next=null; 7while(head!=null){ 8ListNodenext=head.next; 9head.next=pre; 10pre=head; 11head=next; 12} 13returnpre; 14} 15}
递归版
1publicclassSolution{ 2publicListNodereverseList(ListNodehead){ 3if(head==null||head.next==null)returnhead; 4ListNodepre=head; 5head=head.next; 6ListNodenewhead=reverseList(head); 7pre.next=null; 8head.next=pre; 9returnnewhead; 10 11} 12}
相关文章推荐
- 【leetcode】206.Reverse Linked List
- 【LeetCode】206. Reverse Linked List
- 【leetcode】206. Reverse Linked List My Submissions Question
- LeetCode-206. Reverse Linked List
- LeetCode 206. Reverse Linked List
- LeetCode-206. Reverse Linked List
- LeetCode 206. Reverse Linked List
- [LeetCode] 206. Reverse Linked List
- LeetCode 206. Reverse Linked List
- 【LeetCode】206. Reverse Linked List
- [leetcode]206. Reverse Linked List
- 206. Reverse Linked List leetcode list
- Leetcode-206. Reverse Linked List
- [LeetCode]206. Reverse Linked List&92. Reverse Linked List II
- Leetcode 206. Reverse Linked List
- LeetCode 206. Reverse Linked List
- Leetcode题解 206. Reverse Linked List
- Leetcode 206. Reverse Linked List
- Leetcode206. Reverse Linked List
- [leetcode] 206.Reverse Linked List