| 60 | //============================CODE======================== |
| 61 | |
| 62 | class Solution { |
| 63 | public: |
| 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 | }; |
nothing calls this directly
no outgoing calls
no test coverage detected