Submission Detail

33 / 33 test cases passed.
Status:

Accepted

Runtime: 22 ms
Memory Usage: 13.6 MB
Submitted: 0 minutes ago
loading
Runtime Error Message:
Last executed input:
Input:
Output:
Expected:

Accepted Solutions Runtime Distribution

0
5
10
15
20
25
30
35
5
10
15
python
You are here!
Your runtime beats 37.66 % of python submissions.
Runtime (ms)
Distribution (%)

0
5
10
15
20
25
30
35
5
10
15
Zoom area by dragging across this chart

Accepted Solutions Memory Distribution

13500
13300
13350
13400
13450
13550
13600
13650
13700
5
10
15
20
25
30
35
python
You are here!
Your memory usage beats 38.03 % of python submissions.
Memory (KB)
Distribution (%)

13500
13300
13350
13400
13450
13550
13600
13650
13700
10
20
30
Zoom area by dragging across this chart

Invite friends to challenge Binary Tree Zigzag Level Order Traversal


Submitted Code: 0 minutes ago

Language: python

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# Definition for a binary tree node.
# class TreeNode(object):
# def __init__(self, val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
class Solution(object):
def zigzagLevelOrder(self, root):
"""
:type root: TreeNode
:rtype: List[List[int]]
"""
queue = []
next_queue = []
lot = []
z_det = 2
if (root == None):
return lot
queue.append(root)
while (len(queue) > 0):
level = []
for n in queue:
if (n.left != None):
next_queue.append(n.left)
if (n.right != None):
next_queue.append(n.right)
level.append(n.val)
if (z_det % 2 == 0):
lot.append(level)
else:
level.reverse()
lot.append(level)
z_det += 1
queue = next_queue
next_queue = []
return lot
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX