码迷,mamicode.com
首页 > 其他好文 > 详细

leetcode-easy-trees-102. Binary Tree Level Order Traversal-YES

时间:2019-06-14 12:28:42      阅读:86      评论:0      收藏:0      [点我收藏+]

标签:nod   span   else   turn   dea   traversal   code   nbsp   efi   

mycode  98.56%

# 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):
    def levelOrder(self, root):
        """
        :type root: TreeNode
        :rtype: List[List[int]]
        """
        def deal(root,level):
            if not root:
                return 
            if len(self.res) <= level:
                self.res.append([root.val])
            else:
                self.res[level].append(root.val)
            deal(root.left,level+1)
            deal(root.right,level+1)
        self.res = []
        deal(root,0)
        return self.res

 

leetcode-easy-trees-102. Binary Tree Level Order Traversal-YES

标签:nod   span   else   turn   dea   traversal   code   nbsp   efi   

原文地址:https://www.cnblogs.com/rosyYY/p/11022475.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!