zl程序教程

您现在的位置是:首页 >  后端

当前栏目

算法-链表中倒数第k个结点详解编程语言

链表算法编程语言 详解 结点 倒数第
2023-06-13 09:20:44 时间
 ListNode *next;  ListNode(int x): val(x), next(NULL) {} class Solution{ public:  ListNode* FindKthToTail(ListNode* pListHead, unsigned int k){  if(pListHead == NULL)  return pListHead;  if(k  = 0)  return NULL;  // point to the first note  ListNode* pSlow = pListHead;  ListNode* pFast = pListHead;    // move the pFast by k-1 step  int i=1;  for(; i k   pFast != NULL; i++){  pFast = pFast- next;  }  if(pFast == NULL)  return NULL;  // pFast point to the k-th note  // pSlow point to the 1-th note  while(pFast- next){  pSlow = pSlow- next;  pFast = pFast- next;  }  return pSlow;  } int main()  return 0; }

原创文章,作者:Maggie-Hunter,如若转载,请注明出处:https://blog.ytso.com/15314.html

cgo