We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 4f626ba commit 9b24508Copy full SHA for 9b24508
.DS_Store
6 KB
easy/reverse-linked-list/Solution.java
@@ -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