MCPcopy
hub / github.com/HuberTRoy/leetCode / helper

Method helper

Tree/BinaryTreeMaximumPathSum.py:142–161  ·  view source on GitHub ↗
(root)

Source from the content-addressed store, hash-verified

140 self.maxes = -float('inf')
141
142 def helper(root):
143 myValue = root.val
144 if not root.left and not root.right:
145 self.maxes = myValue if myValue > self.maxes else self.maxes
146 return myValue
147
148 valueLeft, valueRight = -float('inf'), -float('inf')
149
150 if root.left:
151 valueLeft = helper(root.left)
152
153 if root.right:
154 valueRight = helper(root.right)
155
156 # judge left to right is max or not.
157
158 self.maxes = max([myValue + valueLeft, myValue + valueRight, myValue + valueLeft + valueRight, myValue, self.maxes])
159
160 # return to parent
161 return max(myValue + max(valueLeft, valueRight), myValue)
162
163 helper(root)
164 return self.maxes

Callers

nothing calls this directly

Calls 1

helperFunction · 0.50

Tested by

no test coverage detected