{"size": 287, "ext": "js", "max_stars_repo_path": "awesome-coding-js/LinkedList/双指针/链表倒数第k个节点.js", "max_stars_repo_name": "chimyking/leetcode-js-chimy", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "awesome-coding-js/LinkedList/双指针/链表倒数第k个节点.js", "max_issues_repo_name": "chimyking/leetcode-js-chimy", "max_issues_repo_issues_event_min_datetime": "2019-07-21T02:32:15.000Z", "max_issues_repo_issues_event_max_datetime": "2021-05-11T23:49:32.000Z", "max_forks_repo_path": "awesome-coding-js/LinkedList/双指针/链表倒数第k个节点.js", "max_forks_repo_name": "chimyking/leetcode-js-chimy", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 42, "max_forks_count": null, "avg_line_length": 15.1052631579, "max_line_length": 36, "alphanum_fraction": 0.5853658537}
/**
 * 输入一个链表，输出该链表中倒数第k个结点。
 */

const findKthToTail = (head, k) => {
	if (!head || !k) return null
	let front = head
	let result = head
	let index = 1
	while (front.next) {
		index++
		front = front.next
		if (index > k) {
			result = result.next
		}
	}
	return k <= index && result
}
