【发布时间】:2016-06-22 16:43:44
【问题描述】:
我用来最小化一棵树的以下代码看起来很糟糕。当然有一种方法可以简化这一点并使用函数而不是 int.MaxValue
if depth%2==1:
min = 9999
for child in currentRoot.children:
if child.score < min:
min = child.score
currentRoot.score = min
else:
max = -9999
for child in currentRoot.children:
if child.score > max:
max = child.score
currentRoot.score = max
return currentRoot.score
【问题讨论】:
-
我的一个想法是否定树的每一层的分数,这样我总能找到最大值,但这似乎有点棘手,因为我可以将它们全部反转并且需要根据叶子的深度找到分钟。