mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-10 18:48:13 +08:00
45 lines
1.6 KiB
HTML
45 lines
1.6 KiB
HTML
<p>给你一棵二叉树,它的根为 <code>root</code> 。请你删除 1 条边,使二叉树分裂成两棵子树,且它们子树和的乘积尽可能大。</p>
|
||
|
||
<p>由于答案可能会很大,请你将结果对 10^9 + 7 取模后再返回。</p>
|
||
|
||
<p> </p>
|
||
|
||
<p><strong>示例 1:</strong></p>
|
||
|
||
<p><strong><img alt="" src="https://assets.leetcode-cn.com/aliyun-lc-upload/uploads/2020/02/02/sample_1_1699.png" style="height: 200px; width: 495px;"></strong></p>
|
||
|
||
<pre><strong>输入:</strong>root = [1,2,3,4,5,6]
|
||
<strong>输出:</strong>110
|
||
<strong>解释:</strong>删除红色的边,得到 2 棵子树,和分别为 11 和 10 。它们的乘积是 110 (11*10)
|
||
</pre>
|
||
|
||
<p><strong>示例 2:</strong></p>
|
||
|
||
<p><img alt="" src="https://assets.leetcode-cn.com/aliyun-lc-upload/uploads/2020/02/02/sample_2_1699.png" style="height: 200px; width: 495px;"></p>
|
||
|
||
<pre><strong>输入:</strong>root = [1,null,2,3,4,null,null,5,6]
|
||
<strong>输出:</strong>90
|
||
<strong>解释:</strong>移除红色的边,得到 2 棵子树,和分别是 15 和 6 。它们的乘积为 90 (15*6)
|
||
</pre>
|
||
|
||
<p><strong>示例 3:</strong></p>
|
||
|
||
<pre><strong>输入:</strong>root = [2,3,9,10,7,8,6,5,4,11,1]
|
||
<strong>输出:</strong>1025
|
||
</pre>
|
||
|
||
<p><strong>示例 4:</strong></p>
|
||
|
||
<pre><strong>输入:</strong>root = [1,1]
|
||
<strong>输出:</strong>1
|
||
</pre>
|
||
|
||
<p> </p>
|
||
|
||
<p><strong>提示:</strong></p>
|
||
|
||
<ul>
|
||
<li>每棵树最多有 <code>50000</code> 个节点,且至少有 <code>2</code> 个节点。</li>
|
||
<li>每个节点的值在 <code>[1, 10000]</code> 之间。</li>
|
||
</ul>
|