<commit_before>#!/usr/bin/env python
# coding=utf-8

# Definition for a binary tree node.
# class TreeNode(object):
#     def __init__(self, x):
#         self.val = x
#         self.left = None
#         self.right = None

class Solution(object):
    
    maxStep = -1
    ret = []
    def largestValues(self, root):
        """
        :type root: TreeNode
        :rtype: List[int]
        """
        self.dfs(root,0)
        return self.ret
        
    def dfs(self, node, step):
        if not node:
            return
        if step > self.maxStep:
            self.ret.append(node.val)
            self.maxStep = step
        else:
            self.ret[step] = max(self.ret[step],node.val)
        self.dfs(node.left,step+1)
        self.dfs(node.right,step+1)
        <commit_msg>513 accepted!<commit_after>#!/usr/bin/env python
# coding=utf-8

'''
1、复习了用队列来做bfs的知识点
2、学到了python中any来巧妙处理队列中元素的存在与否
'''

# Definition for a binary tree node.
# class TreeNode(object):
#     def __init__(self, x):
#         self.val = x
#         self.left = None
#         self.right = None

class Solution(object):
    
    maxStep = -1
    ret = []
    def largestValues(self, root):
        """
        :type root: TreeNode
        :rtype: List[int]
        """
        maxes = []
        row = [root]
        while any(row):
            maxes.append(max([n.val for n in row]))
            tmp = []
            for node in row:
                for kid in (node.left,node.right):
                    if kid: tmp.append(kid)
            row = tmp
        return maxes
            
            
        
        
{'fraction_non_alphanumeric': 0.1221183800623053, 'fraction_numerical': 0.007476635514018692, 'mean_word_length': 1.513302034428795, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2685470', 'n_tokens_mistral': 541, 'n_tokens_neox': 539, 'n_words': 117}