206. Reverse Linked List (E)
来源:互联网 发布:音乐视频剪辑软件 编辑:程序博客网 时间:2024/06/08 04:58
Rt
Iterator Solution:
/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val = x; } * } */public class Solution { public ListNode reverseList(ListNode head) { if(head==null||head.next==null) return head; ListNode iter=head.next; head.next=null; while(iter!=null){ ListNode temp=head; head=iter; iter=iter.next; head.next=temp; } return head; }}
recursion solution:
/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val = x; } * } */public class Solution { public ListNode reverseList(ListNode head) { if(head==null||head.next==null) return head; ListNode temp=reverseList(head.next); head.next.next=head; head.next=null; return temp; }}
0 0
- (E)206. Reverse Linked List
- 206. Reverse Linked List (E)
- 206. Reverse Linked List
- 206. Reverse Linked List
- 206. Reverse Linked List
- 206. Reverse Linked List
- 206. Reverse Linked List
- 206. Reverse Linked List
- 206. Reverse Linked List
- 206. Reverse Linked List
- 206. Reverse Linked List
- 206. Reverse Linked List
- 206. Reverse Linked List
- 206. Reverse Linked List
- 206. Reverse Linked List
- 206. Reverse Linked List
- 206. Reverse Linked List
- 206. Reverse Linked List
- 九种排序算法总结与Java实现
- 699UVa"\b"的问题
- 写System权限的APP
- 金明的预算方案(开心的金明升级版)
- 数据挖掘中的模式发现(二)Apriori算法
- 206. Reverse Linked List (E)
- 【微信开发】-- 企业转账到用户
- JavaScript 正则表达式的规则和使用
- Android 如何永久性开启adb 的root权限
- 魔术方法的应用
- [python]爬虫存入本地
- 制作水果忍者-JS-4
- 设计模式笔记之----单例模式
- 【微信开发】-- 企业转账到用户_0