Skip to content

Commit 1749c18

Browse files
Create ReverseLL.java
1 parent ca283e3 commit 1749c18

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
public class Main {
3+
4+
static class Node {
5+
int data;
6+
Node next;
7+
8+
public Node(int data) {
9+
this.data = data;
10+
this.next = null;
11+
}
12+
}*/
13+
public static Node reverseList(Node head) {
14+
Node prev = null;
15+
Node current = head;
16+
Node next = null;
17+
18+
while (current != null) {
19+
next = current.next;
20+
21+
current.next = prev;
22+
23+
prev = current;
24+
current = next;
25+
}
26+
27+
return prev;
28+
}
29+
30+

0 commit comments

Comments
 (0)