There was an error while loading. Please reload this page.
2 parents 66c3a56 + 2599e8c commit f337214Copy full SHA for f337214
Reverse_Linked_List.java
@@ -0,0 +1,23 @@
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
+
12
+class Solution {
13
+ public ListNode reverseList(ListNode head) {
14
+ ListNode newHead = null;
15
+ while (head != null) {
16
+ ListNode next = head.next;
17
+ head.next = newHead;
18
+ newHead = head;
19
+ head = next;
20
+ }
21
+ return newHead;
22
23
+}
0 commit comments