✅ (C++ / Python) Easy One Pass 0 ms Solution 🔥
Complexity\n- Time complexity: O(n)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity: O(n)\n Add your space complexity here, e.g. O(n) \n\n# C+
# Complexity\n- Time complexity: O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(n)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# C++\n```\nclass Solution {\npublic:\n    ListNode* removeNthFromEnd(ListNode* head, int n) {\n        vector<ListNode*> nodes;\n        ListNode* temp = head;\n        while (temp)\n        {\n            nodes.push_back(temp);\n            temp = temp->next;\n        }\n        if (nodes.size()==1) return NULL;\n        if (nodes.size()-n<=0) return nodes[1];\n        ListNode* node = nodes[nodes.size()-1-n];\n        node->next = node->next->next;\n        return head;\n    }\n};\n```\n\n# Python\n```\nclass Solution(object):\n    def removeNthFromEnd(self, head, n):\n        """\n        :type head: ListNode\n        :type n: int\n        :rtype: ListNode\n        """\n        nodes = []\n        temp = head\n        while (temp):\n            nodes.append(temp)\n            temp = temp.next\n        if (len(nodes)==1): return None\n        if (len(nodes)-n<=0): return nodes[1]\n        node = nodes[len(nodes)-1-n]\n        node.next= node.next.next\n        return head\n```\n\nUpvote if this helps please \uD83D\uDE42
['Array', 'Python', 'C++']