• 树的练习(6)


     很显然,这与前面的一题的本质区别是,不再是简单的追加。要区分追加的分类。

    # Definition for a binary tree node.
    # class TreeNode:
    #     def __init__(self, x):
    #         self.val = x
    #         self.left = None
    #         self.right = None
    
    class Solution:
        def levelOrder(self, root: TreeNode) -> List[List[int]]:
            if not root: return []
            res, queue = [], collections.deque()
            queue.append(root)
            while queue:
                tmp = []
                for _ in range(len(queue)):
                    node = queue.popleft()
                    tmp.append(node.val)
                    if node.left: queue.append(node.left)
                    if node.right: queue.append(node.right)
                res.append(tmp)
            return res
    # Definition for a binary tree node.
    # class TreeNode:
    #     def __init__(self, x):
    #         self.val = x
    #         self.left = None
    #         self.right = None
    
    class Solution:
        def levelOrder(self, root: TreeNode) -> List[List[int]]:
            if not root: return []
            res, queue = [],[root]
            while queue:
                tmp=[]
                for _ in range(len(queue)):
                    node = queue.pop(0)
                    tmp.append(node.val)
                    if node.left: queue.append(node.left)
                    if node.right: queue.append(node.right)
                res.append(tmp)
            return res
  • 相关阅读:
    Oracle EBS json
    OAF--基础
    Oracle EBS FA 本年折旧
    Oracle EBS FA 获取累计折旧
    SOAP REST
    Oracle EBS FA 资产取值
    Java ——基础语法
    PL/SQL APIs for Concurrent Processing
    Using Globals in Oracle Reports (Doc ID 34751.1)
    Using SRW Packaged Procedures In Reports (Doc ID 61643.1)
  • 原文地址:https://www.cnblogs.com/topass123/p/12764556.html
Copyright © 2020-2023  润新知