(node, res)
| 6 | |
| 7 | // 返回经过root的且只能取左右一个节点的路径长度 |
| 8 | function 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) { |
no outgoing calls
no test coverage detected