Skip to content

Commit

Permalink
Create RemoveLLElements.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
kshitiz11101 authored Apr 29, 2024
1 parent 7b19718 commit 8161dd2
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions Linked Lists/RemoveLLElements.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
class Solution {
public:
ListNode* removeElements(ListNode* head, int val) {
if(head==NULL)
return head;
while(head!=NULL && head->val==val){
head=head->next;
}

ListNode*prev=NULL;
ListNode*curr=head;
while(curr!=NULL){
if(curr->val==val){
prev->next=curr->next;
curr=curr->next;
}
else{
prev=curr;
curr=curr->next;
}
}
return head;
}
};

0 comments on commit 8161dd2

Please sign in to comment.