Class Solution
java.lang.Object
g1301_1400.s1339_maximum_product_of_splitted_binary_tree.Solution
1339 - Maximum Product of Splitted Binary Tree.<p>Medium</p>
<p>Given the <code>root</code> of a binary tree, split the binary tree into two subtrees by removing one edge such that the product of the sums of the subtrees is maximized.</p>
<p>Return <em>the maximum product of the sums of the two subtrees</em>. Since the answer may be too large, return it <strong>modulo</strong> <code>10<sup>9</sup> + 7</code>.</p>
<p><strong>Note</strong> that you need to maximize the answer before taking the mod and not after taking it.</p>
<p><strong>Example 1:</strong></p>
<p><img src="https://assets.leetcode.com/uploads/2020/01/21/sample_1_1699.png" alt="" /></p>
<p><strong>Input:</strong> root = [1,2,3,4,5,6]</p>
<p><strong>Output:</strong> 110</p>
<p><strong>Explanation:</strong> Remove the red edge and get 2 binary trees with sum 11 and 10. Their product is 110 (11*10)</p>
<p><strong>Example 2:</strong></p>
<p><img src="https://assets.leetcode.com/uploads/2020/01/21/sample_2_1699.png" alt="" /></p>
<p><strong>Input:</strong> root = [1,null,2,3,4,null,null,5,6]</p>
<p><strong>Output:</strong> 90</p>
<p><strong>Explanation:</strong> Remove the red edge and get 2 binary trees with sum 15 and 6.Their product is 90 (15*6)</p>
<p><strong>Constraints:</strong></p>
<ul>
<li>The number of nodes in the tree is in the range <code>[2, 5 * 10<sup>4</sup>]</code>.</li>
<li><code>1 <= Node.val <= 10<sup>4</sup></code></li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
sumTree
-
maxProduct
-