deno.land / x / masx200_leetcode_test@10.6.5 / 4ueAj6 / 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
import { ListNode as Node } from "../reverse-linked-list/ListNode.ts";
export default function insert( head: Node | null, insertVal: number,): Node | null { if (!head) { const node = new Node(insertVal); node.next = node; return node; } const node = new Node(insertVal);
let cur = head; while (cur.next !== head) { const nextval = cur.next?.val; if (typeof nextval == "undefined") { throw Error("none next node"); } if (cur.val <= insertVal && nextval >= insertVal) { break; } if (cur.val > nextval) { if (nextval >= insertVal) { break; } else if (cur.val <= insertVal) { break; } } if (cur.next) { cur = cur.next; } else { throw Error("none next node"); } } node.next = cur.next; cur.next = node; return head;}
masx200_leetcode_test

Version Info

Tagged at
a year ago