-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay27.java
More file actions
45 lines (43 loc) · 1008 Bytes
/
Copy pathDay27.java
File metadata and controls
45 lines (43 loc) · 1008 Bytes
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
//Delete in a doubly linked list
// https://bit.ly/3QlEoMx
class Solution {
public Node deleteNode(Node head, int x) {
// code here
Node curr=head;
if(x==1){
head.next.prev=null;
return head.next;
}
while(x>2){
curr=curr.next;
x--;
}
Node del=curr.next;
curr.next=del.next;
if(del.next!=null)
del.next.prev=curr;
return head;
}
}
//TC:O(n)
//SC:O(1)
//Reverse a doubly linked list
// https://bit.ly/3w6hUaa
class Solution {
public DLLNode reverseDLL(DLLNode head) {
// Your code here
DLLNode curr=head;
DLLNode prev=null;
if(head==null || head.next==null) return head;
while(curr!=null){
DLLNode nextnode=curr.next;
curr.prev=nextnode;
curr.next=prev;
prev=curr;
curr=nextnode;
}
return prev;
}
}
//TC:O(N)
//SC:O(1)