-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreversenodes.java
More file actions
62 lines (49 loc) · 1.27 KB
/
Copy pathreversenodes.java
File metadata and controls
62 lines (49 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
class ListNode {
int val;
ListNode next;
ListNode() {
}
ListNode(int x) {
this.val = x;
}
ListNode(int val, ListNode next) {
this.val = val;
this.next = next;
}
}
public class reversenodes {
public ListNode reverseList(ListNode head){
ListNode prev = null;
ListNode curr = head;
while(curr!=null){
ListNode next = curr.next;
curr.next = prev;
prev=curr;
curr=next;
}
return prev;
}
public static void main(String[] args) {
// reversenodes rn = new reversenodes();
ListNode head = new ListNode(1);
ListNode second = new ListNode(2);
ListNode third = new ListNode(3);
ListNode fourth= new ListNode(4);
ListNode fifth = new ListNode(5);
head.next=second;
second.next=third;
third.next=fourth;
fourth.next=fifth;
fifth.next=null;
ListNode dummy = new ListNode(0,head);
ListNode grpprev = dummy;
int k =
while(true){
}
// ListNode ptr1 = head;
// while(ptr1!=null){
// System.out.println(ptr1.val);
// ptr1=ptr1.next;
// }
}
}