From 4a4122312d4e99ac821bac8e8ac6e423525c587b Mon Sep 17 00:00:00 2001 From: lokendra1704 Date: Wed, 15 Jul 2020 00:54:11 +0530 Subject: [PATCH] Using get function of dictionary --- Medium/102.BinaryTreeLevelOrderTraversal.py | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) 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