Skip to content

Commit 2b2781a

Browse files
Reverse a linked list
1 parent 3a8723a commit 2b2781a

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

LinkedList/LinkedList.java

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Solution {
2+
public ListNode reverseList(ListNode head) {
3+
ListNode curr=head,prev=null,temp=head,fix;
4+
if(head==null || head.next==null)
5+
return head;
6+
ListNode newhead=reverseList(head.next);
7+
ListNode headnext=head.next;
8+
headnext.next=head;
9+
head.next=null;
10+
return newhead;
11+
}
12+
}

0 commit comments

Comments
 (0)