Solved LeetCode program · 969 of 1,000
#1339 · Maximum Product of Splitted Binary Tree
Original English source
Keep a shared values holding 1, 2, 3, 4, 5, and 6. Keep a shared lefts holding 1, 3, 5, -1, -1, and -1. Keep a shared rights holding 2, 4, -1, -1, -1, and -1. Keep a shared flow of 0. Keep a shared total of 0. Keep a shared best of 0.
To gather from node (a whole number). If node is less than 0, set flow to 0, return. Gather from item node of lefts. The leftsize is flow. Gather from item node of rights. The rightsize is flow. Set flow to item node of values plus leftsize plus rightsize.
To measure from node (a whole number). If node is less than 0, set flow to 0, return. Measure from item node of lefts. The leftsize is flow. Measure from item node of rights. The rightsize is flow. The whole is item node of values plus leftsize plus rightsize.
If whole is less than total.
The cut is whole times (total minus whole). If cut is more than best, set best to cut. Set flow to whole.
Gather from 0. Set total to flow. Measure from 0. Show best.
Expected stdout
110