Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ADDED CODE FOR Medium/Remove_Nth_Node_From_End_of_List.cpp #107

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions PARTICIPANTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,14 @@
- 🔭 Connect with me: **[jainmalaykumar](https://github.com/jainmalaykumar))**

---

### Connect with me:

<img align="right" src="https://avatars3.githubusercontent.com/AUM-PATEL2624?size=100" width="100px;" alt=""/>

- 👨‍💻 My name is **Aum Patel**
- 🌱 I’m a Student.
- 📫 Reach me: **aumpatelc36@gmail.com**
- 🔭 Connect with me: **[AUM-PATEL2624](https://github.com/AUM-PATEL2624)**

---
46 changes: 46 additions & 0 deletions cpp/Medium/Remove_Nth_Node_From_End_of_List.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//Code By - AUM PATEL

/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode() : val(0), next(nullptr) {}
* ListNode(int x) : val(x), next(nullptr) {}
* ListNode(int x, ListNode *next) : val(x), next(next) {}
* };
*/
class Solution {
public:
ListNode* removeNthFromEnd(ListNode* head, int n) {
int number=1;
ListNode* temp = head;
while(temp -> next != NULL){
temp = temp->next;
number ++;
}
int pos = number-n+1;
if(pos == 1){
ListNode* temp = head;
head = head -> next;
temp -> next = NULL;
delete temp;
}

else{
ListNode* curr = head;
ListNode* prev = NULL;

int cnt = 1;
while(cnt < pos ){
prev = curr;
curr = curr-> next;
cnt ++;
}
prev -> next = curr -> next;
curr -> next = NULL;
}
return head;

}
};