Skip to content

Commit 4b4877f

Browse files
committed
https://leetcode.cn/problems/er-cha-shu-ren-wu-diao-du/
1 parent c196703 commit 4b4877f

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ Step 2. Add the dependency
4545

4646
<summary>展开查看</summary>
4747

48+
https://leetcode.cn/problems/er-cha-shu-ren-wu-diao-du/
49+
4850
https://leetcode.cn/problems/er-cha-sou-suo-shu-de-di-kda-jie-dian-lcof/
4951

5052
https://leetcode.cn/problems/numbers-at-most-n-given-digit-set/

er-cha-shu-ren-wu-diao-du/index.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { TreeNode } from "../binary-tree-inorder-traversal/TreeNode.ts";
2+
3+
function minimalExecTime(root: TreeNode | null) {
4+
const res = execTime(root);
5+
return res[0];
6+
}
7+
8+
function execTime(node: TreeNode | null): [number, number] {
9+
if (node == null) {
10+
// [0]执行完当前节点最小耗时,[1]当前node为根的时间串行之和
11+
return [0, 0];
12+
}
13+
// 获取左右子树的值
14+
const leftTime = execTime(node.left);
15+
const rightTime = execTime(node.right);
16+
// 左右子树节点之和
17+
const sum = leftTime[1] + rightTime[1];
18+
// 当前节点执行完的最小消耗时间
19+
const minTime =
20+
Math.max(Math.max(leftTime[0], rightTime[0]), sum / 2) + node.val;
21+
return [minTime, sum + node.val];
22+
}
23+
export default minimalExecTime;

0 commit comments

Comments
 (0)