-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution206.java
More file actions
43 lines (37 loc) · 916 Bytes
/
Copy pathSolution206.java
File metadata and controls
43 lines (37 loc) · 916 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/**
* @Title: Solution206.java——
* @Package EasyCode_01
* @Description: TODO
* @author msdumin@gmail.com
* @date 2019年3月27日 上午10:04:25
* @version V1.0
*/
package EasyCode_01;
/**
* @ClassName: Solution206——反转链表
* @Description: TODO
* 输入: 1->2->3->4->5->NULL
输出: 5->4->3->2->1->NULL
* @author msdumin@gmail.com
* @date 2019年3月27日 上午10:04:25
*/
public class Solution206 {
public static ListNode reverseList(ListNode head) {
ListNode pre = null;
ListNode cur = head;
while(cur != null){
ListNode next = cur.next;
cur.next = pre;
pre = cur;
cur = next;
}
return pre;
}
public static void main(String[] args) {
int[] arr = {1,2,3,4,5};
ListNode head = new ListNode(arr);
System.out.println(head);
ListNode myHead = reverseList(head);
System.out.println(myHead);
}
}