deno.land / x / masx200_leetcode_test@10.6.5 / reverse-nodes-in-k-group / 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
25
26
27
28
import { getEndOfList } from "../merge-in-between-linked-lists/get_end_of_list.ts";import { get_deep_next_of_list } from "../reverse-linked-list-ii/get_deep_next_of_list.ts";import reverse_Linked_List from "../reverse-linked-list/index.ts";import { ListNode } from "../reverse-linked-list/ListNode.ts";
import { greater_equal_length_of_list } from "./greater_equal_length_of_list.ts";
function reverseKGroup(head: ListNode | null, k: number): ListNode | null { if (k <= 1) return head; if (!head) return null; if (greater_equal_length_of_list(head, k)) { const res = new ListNode(0, head); const end = get_deep_next_of_list(head, k - 1);
const next = end.next;
end.next = null; res.next = reverse_Linked_List(head); if (res.next) { getEndOfList(res.next).next = reverseKGroup(next, k); } return res.next; } else { return head; }}export default reverseKGroup;
masx200_leetcode_test

Version Info

Tagged at
a year ago