515. Find Largest Value in Each Tree Row
- Find Largest Value in Each Tree Row python solution
题目描述
You need to find the largest value in each row of a binary tree.
解析
充分使用python的自带函数——map和itertools.zip_longest迭代器。具体功能见下图
def largestValues(self, root):
if not root:
return []
left = self.largestValues(root.left)
right = self.largestValues(root.right)
return [root.val] + list(map(max, itertools.zip_longest(left, right, fillvalue=-math.inf)))
Reference
https://leetcode.com/problems/find-largest-value-in-each-tree-row/discuss/99045/1-liner-Python-Divide-and-conquer
来源:CSDN
作者:orientliu96
链接:https://blog.csdn.net/Orientliu96/article/details/103697050