class Solution {
public:
/**
* @param head: The first node of linked list.
* @param n: An integer.
* @return: Nth to last node of a singly linked list.
*/
ListNode *nthToLast(ListNode *head, int n) {
// write your code here
ListNode *dummy=new ListNode(0);
dummy->next=head;
head=dummy;
int count,m,l;
count=0;l=0;
while(head->next!=NULL){
head=head->next;
count++;
}
m=count-n;
while(l<m) {
dummy=dummy->next;
l++;
}
return dummy->next;
}
};