From 0921d86dccc2207c02bf48f8c17093016e0c5eb6 Mon Sep 17 00:00:00 2001 From: AUM PATEL Date: Fri, 14 Oct 2022 19:43:12 +0530 Subject: [PATCH 1/2] Added My Details --- PARTICIPANTS.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/PARTICIPANTS.md b/PARTICIPANTS.md index 75e78f1..d2d3d9c 100644 --- a/PARTICIPANTS.md +++ b/PARTICIPANTS.md @@ -121,3 +121,14 @@ - šŸ”­ Connect with me: **[jainmalaykumar](https://github.com/jainmalaykumar))** --- + +### Connect with me: + + + +- šŸ‘Øā€šŸ’» My name is **Aum Patel** +- 🌱 I’m a Student. +- šŸ“« Reach me: **aumpatelc36@gmail.com** +- šŸ”­ Connect with me: **[AUM-PATEL2624](https://github.com/AUM-PATEL2624)** + + --- From ed6c9408030ccbb7e7c966aba7b62f360fe9963b Mon Sep 17 00:00:00 2001 From: AUM PATEL Date: Fri, 14 Oct 2022 19:45:23 +0530 Subject: [PATCH 2/2] added code for Remove Nth Node From End of List --- .../Remove_Nth_Node_From_End_of_List.cpp | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 cpp/Medium/Remove_Nth_Node_From_End_of_List.cpp diff --git a/cpp/Medium/Remove_Nth_Node_From_End_of_List.cpp b/cpp/Medium/Remove_Nth_Node_From_End_of_List.cpp new file mode 100644 index 0000000..a0edd39 --- /dev/null +++ b/cpp/Medium/Remove_Nth_Node_From_End_of_List.cpp @@ -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; + + } +};