MCPcopy
hub / github.com/azl397985856/leetcode / helper

Function helper

daily/answers/687.longest-univalue-path.js:8–20  ·  view source on GitHub ↗
(node, res)

Source from the content-addressed store, hash-verified

6
7// 返回经过root的且只能取左右一个节点的路径长度
8function helper(node, res) {
9 if (node === null) return 0;
10 const l = helper(node.left, res);
11 const r = helper(node.right, res);
12 let lcnt = 0;
13 let rcnt = 0;
14 if (node.left && node.val === node.left.val) lcnt = lcnt + l + 1;
15 if (node.right && node.val === node.right.val) rcnt = rcnt + r + 1;
16
17 res.max = Math.max(res.max, lcnt + rcnt);
18
19 return Math.max(lcnt, rcnt);
20 }
21 /**
22 * Definition for a binary tree node.
23 * function TreeNode(val) {

Callers 1

longestUnivaluePathFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected