MCPcopy Create free account
hub / github.com/Vishruth-S/CompetitiveCode / Solution

Class Solution

LeetCode_problems/Remove Nth Node from End/solution.cpp:62–85  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

60//============================CODE========================
61
62class Solution {
63public:
64 ListNode* removeNthFromEnd(ListNode* head, int n) {
65
66 ListNode* start = new ListNode(0);
67 start->next = head;
68
69 ListNode* fast = start;
70 ListNode* slow = start;
71
72 for(int i = 1; i <= n; ++i)
73 fast = fast->next;
74
75 while(fast->next != NULL)
76 {
77 fast = fast->next;
78 slow = slow->next;
79 }
80
81 slow->next = slow->next->next;
82
83 return start->next;
84 }
85};

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected