Could anyone help me find the problem of my code? I couldn't think of where might go wrong. Thanks!

```
class Solution {
public:
ListNode* removeNthFromEnd(ListNode* head, int n) {
ListNode* p = head;
ListNode* q = head;
for(int i = 0 ; i < n ; i++){
q = q->next;
}
while(q->next != NULL){
p = p->next;
q = q->next;
}
ListNode* tmp = p->next;
p->next = p->next->next;
delete tmp;
return head;
}
};
```