forked from mranjan15/Java-Code-solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDelNSkipM.java
35 lines (27 loc) · 826 Bytes
/
DelNSkipM.java
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
//https://practice.geeksforgeeks.org/problems/delete-n-nodes-after-m-nodes-of-a-linked-list/1
class Solution
{ // 2 1
static void linkdelete(Node head, int M, int N)
{
if(head== null) return;
Node temp = head;
while(temp.next != null) {
int m = M;
int n = N;
while(m > 1) {
m--;
if(temp.next != null)
temp = temp.next;
}
Node curr = temp;
while(n > 0) {
n--;
if(temp.next != null)
temp = temp.next;
}
curr.next = temp.next;
if(temp.next != null)
temp = temp.next;
}
}
}