Skip to content

Commit

Permalink
Create RemoveEveryKthNode.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
kshitiz11101 authored Apr 29, 2024
1 parent 131cb61 commit 7b19718
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions Linked Lists/RemoveEveryKthNode.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
class Solution {
public:
Node* deleteK(Node *head,int K){
//Your code here
if(K==1)
return NULL;
int cnt=0;
Node*prev=NULL;
Node*curr=head;
while(curr!=NULL){
cnt++;
if(cnt==K){
prev->next=curr->next;
cnt=0;
}
prev=curr;
curr=curr->next;
}
return head;
}
};

0 comments on commit 7b19718

Please sign in to comment.