deno.land / x / masx200_leetcode_test@10.6.5 / convert-bst-to-greater-tree / index.ts

نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import { TreeNode } from "../binary-tree-inorder-traversal/TreeNode.ts";
export default function convertBST(root: TreeNode | null): TreeNode | null { let pre = 0; let cur: TreeNode | null | undefined = root; const stack: (TreeNode | null | undefined)[] = []; while (cur || stack.length !== 0) { while (cur) { stack.push(cur); cur = cur.right; } cur = stack.pop(); if (cur) { cur.val += pre; pre = cur.val; cur = cur?.left; } } return root;}
masx200_leetcode_test

Version Info

Tagged at
a year ago