deno.land / x / masx200_leetcode_test@10.6.5 / partition-list / 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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import { ArrayToListNode } from "../reverse-linked-list/ArrayToListNode.ts";import { ListNode } from "../reverse-linked-list/ListNode.ts";import { ListNodeToArray } from "../reverse-linked-list/ListNodeToArray.ts";
export default function partition( head: ListNode | null, x: number,): ListNode | null { if (!head) return head; if (!head.next) return head; const array = ListNodeToArray(head); const small = array.filter((a) => a < x); const big = array.filter((a) => a >= x); return ArrayToListNode([...small, ...big]);}// function ListNodeToArray(list: ListNode | null): Array<number> {// if (list === null) {// return [];// }// const array: Array<number> = [];// let temp: ListNode | null = list;// while (temp) {// array.push(temp.val);// temp = temp.next;// }// return array;// }// function ArrayToListNode(array: Array<number>): ListNode | null {// if (array.length === 0) {// return null;// }// const list = new ListNode(array[0]);// let cur = list;// for (let i = 1; i < array.length; i++) {// const v = array[i];// const l = new ListNode(v);// cur.next = l;// cur = cur.next;// }// // array.slice(1).reduce((p, v) => {// // const l = new ListNode(v);// // p.next = l;// // return l;// // }, list);// return list;// }
masx200_leetcode_test
leetcode题解和一些测试工具
DocumentationDocumentation
GitHub Repositorymasx200/leetcode-test
GitHub Stars
4

Version Info

Tagged at
4 months ago