-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path0103.binary-tree-zigzag-level-order-traversal.py
62 lines (52 loc) · 1.32 KB
/
0103.binary-tree-zigzag-level-order-traversal.py
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# Category: algorithms
# Level: Medium
# Percent: 58.7%
# pylint: enable=useless-suppression
# pylint: disable=invalid-name, line-too-long, too-few-public-methods
# pylint: disable=missing-class-docstring, missing-function-docstring, missing-module-docstring
#
# Given the root of a binary tree, return the zigzag level order traversal of its nodes' values. (i.e., from left to right, then right to left for the next level and alternate between).
#
#
#
# Example 1:
#
# Input: root = [3,9,20,null,null,15,7]
# Output: [[3],[20,9],[15,7]]
#
# Example 2:
#
# Input: root = [1]
# Output: [[1]]
#
# Example 3:
#
# Input: root = []
# Output: []
#
#
#
# Constraints:
#
# The number of nodes in the tree is in the range [0, 2000].
# -100 <= Node.val <= 100
#
# 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
import unittest
from typing import List, Optional
from leetopenlib.tree import TreeNode, list_to_tree, tree_to_list
# start_marker
class Solution:
def zigzagLevelOrder(self, root: Optional[TreeNode]) -> List[List[int]]:
pass
# end_marker
class TestSolution(unittest.TestCase):
def test_case_1(self):
pass
if __name__ == "__main__":
unittest.main()