Участник:Rublev.mv/maximum-product-of-splitted-binary-tree — различия между версиями
Материал из DISCOPAL
StasFomin (обсуждение | вклад) (Новая страница: «* https://leetcode.com/problems/maximum-product-of-splitted-binary-tree/ <code-java> /** * Definition for a binary tree node. * public class TreeNode { *…») |
StasFomin (обсуждение | вклад) |
||
Строка 41: | Строка 41: | ||
</code-java> | </code-java> | ||
+ | |||
+ | [[Участник:StasFomin|StasFomin]] 16:14, 28 декабря 2020 (MSK): Не проходит тесты: | ||
+ | |||
+ | [[File:maximum-product-of-splitted-binary-tree_2020-12-28_16-13-49_image0.png||800px]] |
Текущая версия на 16:14, 28 декабря 2020
/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode() {} * TreeNode(int val) { this.val = val; } * TreeNode(int val, TreeNode left, TreeNode right) { * this.val = val; * this.left = left; * this.right = right; * } * } */ class Solution { public int maxProduct(TreeNode root) { Set<Integer> s = new HashSet<>(); int t = find(root, s); long max = 0; for (long sum : s) { max = Math.max(max, sum * (t - sum)); } return (int) (max % (100000000)); } public int find(TreeNode root, Set<Integer> s) { if (root == null) return 0; int sum = find(root.left, s) + find(root.right, s) + root.val; s.add(sum); return sum; } }
StasFomin 16:14, 28 декабря 2020 (MSK): Не проходит тесты: