void findLastK(LinkedNode head, int k, int n){
	if (head == NULL || k == 0) return;

	LinkedNode t1 = head;
	LinkedNode t2 = head;
	
	for (int i = 0; i < k - 1; i++){
		if (t1->next != NULL){
			t1 = t1->next;
		}
		else{
			return;
		}
	}
	while (t1->next != NULL){
		t2 = t2->next;
		t1 = t1->next;
	}
	cout << t2->number << endl;
}

相关题目:
求链表的中间结点。
判断单向链表是否形成环状结构。

  

相关文章:

  • 2022-02-14
猜你喜欢
  • 2022-01-27
  • 2022-12-23
  • 2021-12-26
  • 2021-10-21
  • 2022-12-23
  • 2021-10-14
相关资源
相似解决方案