leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

0019.cpp (399B)


0 class Solution {
1 public:
2 ListNode *removeNthFromEnd(ListNode *head, int n) {
3 ListNode *b = head;
5 n++;
6 for (ListNode *a = head; a; a = a->next) {
7 if (!n)
8 b = b->next;
9 else
10 n--;
11 }
12 if (n)
13 head = head->next;
14 else
15 b->next = b->next->next;
16 return head;
17 }
18 };