diff --git a/Medium/102.BinaryTreeLevelOrderTraversal.py b/Medium/102.BinaryTreeLevelOrderTraversal.py index 0eee79f..5def131 100644 --- a/Medium/102.BinaryTreeLevelOrderTraversal.py +++ b/Medium/102.BinaryTreeLevelOrderTraversal.py @@ -45,13 +45,7 @@ def levelOrder(self, root: TreeNode) -> List[List[int]]: for node in queue[depth]: result[depth].append(node.val) if node.left: - if depth+1 not in queue: - queue[depth+1] = [node.left] - else: - queue[depth+1].append(node.left) + queue[depth+1] = queue.get(depth+1,[]).append(node.left) if node.right: - if depth+1 not in queue: - queue[depth+1] = [node.right] - else: - queue[depth+1].append(node.right) + queue[depth+1] = queue.get(depth+1,[]).append(node.right) depth += 1