Simple and Easy to Understand C++ solution
\n/**\n * Definition for singly-linked list.\n * struct ListNode {\n *     int val;\n *     ListNode *next;\n *     ListNode(int x) : val(x), next(NULL) {}\n * 
```\n/**\n * Definition for singly-linked list.\n * struct ListNode {\n *     int val;\n *     ListNode *next;\n *     ListNode(int x) : val(x), next(NULL) {}\n * };\n */\nclass Solution {\npublic:\n    ListNode* removeNthFromEnd(ListNode* head, int n) {\n        int size=0;\n        ListNode* ans=head;\n        ListNode* check=head;\n        while(head){\n            size++;\n            head=head->next;\n        }\n        if(size==1) return NULL;\n        if(size <= n){\n            return ans->next;\n        }\n        for(int i=1;i<size-n;i++){\n            check=check->next;\n        }\n        check->next=check->next->next;\n       return ans;\n    }\n};\n```
[]