deno.land / x / masx200_leetcode_test@10.6.5 / lian-biao-zhong-dao-shu-di-kge-jie-dian-lcof / index.ts

نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
export default function getKthFromEnd( head: ListNode | null, k: number,): ListNode | null { if (!head) return head; if (!head.next) return head; if (k === 0) return null;
let fast: ListNode | null = head; for (let i = k; i > 0; i--) { if (fast) { fast = fast.next; } } if (!fast) return head; let slow: ListNode | null = head; while (fast && slow) { fast = fast.next; slow = slow.next; } return slow;}import { ListNode } from "../reverse-linked-list/ListNode.ts";
masx200_leetcode_test

Version Info

Tagged at
a year ago