Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public int maxProduct(TreeNode root) {
- if(root == null){
- return 0;
- }
- return Math.max(sum(root.left, root.val), sum(root.right, root.val));
- }
- public int sum(TreeNode root, int sumAbove) {
- if(root == null) {
- return 0;
- }
- int left = sum(root.left, root.val);
- int right = sum(root.right, root.val);
- int max = Math.max((left+sumAbove) * (right), (right+sumAbove) * (left));
- max = Math.max(max, root.val);
- return max;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement