The number of nodes in the tree is in the range [0, 2000].
-1000 <= Node.val <= 1000
Test Cases
1 2 3 4 5 6 7 8
# Definition for a binary tree node. # class TreeNode: # def __init__(self, val=0, left=None, right=None): # self.val = val # self.left = left # self.right = right classSolution: deflevelOrder(self, root: Optional[TreeNode]) -> List[List[int]]:
import os import sys sys.path.append(os.path.dirname(os.path.dirname(__file__))) from _utils.binary_tree import build_tree from solution import Solution
from collections import deque from typing importOptional
# Definition for a binary tree node. classTreeNode: def__init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right