Skip to content

Commit 9b24508

Browse files
committed
solution
1 parent 4f626ba commit 9b24508

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

.DS_Store

6 KB
Binary file not shown.
+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* Definition for singly-linked list.
3+
* public class ListNode {
4+
* int val;
5+
* ListNode next;
6+
* ListNode() {}
7+
* ListNode(int val) { this.val = val; }
8+
* ListNode(int val, ListNode next) { this.val = val; this.next = next; }
9+
* }
10+
*/
11+
class Solution {
12+
public ListNode reverseList(ListNode head) {
13+
if (head == null) {
14+
return head;
15+
}
16+
ListNode current = head;
17+
ListNode previous = null;
18+
ListNode next = null;
19+
while (current != null) {
20+
next = current.next;
21+
current.next = previous;
22+
previous = current;
23+
current = next;
24+
}
25+
return previous;
26+
27+
}
28+
}

0 commit comments

Comments
 (0)