Title Link: https://leetcode.com/problems/remove-nth-node-from-end-of-list/
Topic:
Given A linked list, remove the nth node from the end of the list and return its head.
For example,
1->2->3->4->5 N = 2. 1->2->3->5.
Note:
Given n would always be valid.
Try to do the in one pass.
Problem-solving ideas: the need to delete the count of the number of nth, due to the sequential Search feature list. So change the mind, quoting two linked list l1,l2. L1 first to search the number of n, and then l1,l2 to search together until L1 to the end, delete L2 this point on the line.
Class Solution {public: listnode *removenthfromend (listnode *head, int n) { ListNode *point = head; ListNode *answers = head; ListNode *change = head; for (int i = 0; i < n; i++) { if (Point->next = = NULL) return answers->next; Point = point->next; } while (point->next! = NULL) { head = head->next; Point = point->next; } Head->next = head->next->next; return answers;} ;
Reprint Please specify Vanish_dust
Leetcode-remove Nth Node from End of List