思路:设置两个快慢指针former、later,先让快指针走k步,然后两个指针同步走,当快指针走到头时,慢指针就是链表倒数第k个节点。

struct listnode* get_k_end(struct listnode* H,int k)
{
    struct listnode* former=H;
    struct listnode* later=H;
    for(int i=0;i<k;i++)
    {
        former=former->next;
    }
    while(former)
    {
        later=later->next;
        former=former->next;
    }
    return later;
}