题目:
题解:
class Solution:def largestValues(self, root: Optional[TreeNode]) -> List[int]:if root is None:return []ans = []q = [root]while q:maxVal = -inftmp = qq = []for node in tmp:maxVal = max(maxVal, node.val)if node.left:q.append(node.left)if node.right:q.append(node.right)ans.append(maxVal)return ans