deno.land / x / masx200_leetcode_test@10.6.5 / convert-sorted-list-to-binary-search-tree / 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
29
30
import { ListNode, TreeNode } from "../mod.ts";import { get_length_of_list } from "../reverse-linked-list-ii/get_length_of_list.ts";import { buildBST } from "./buildBST.ts";
export default function sortedListbuildBST( head: ListNode | null,): TreeNode | null { if (!head) return null; let node: ListNode | null = head; const n = get_length_of_list(head); // let n = 0;
// while (node) { // node = node.next; // n++; // } node = head; // console.log(JSON.stringify(head)) return buildBST( 0, n - 1, () => node?.val, () => { if (!node) return;
node = node.next; }, );}
masx200_leetcode_test

Version Info

Tagged at
a year ago