<commit_before># Definition for a binary tree node.
# class TreeNode(object):
#     def __init__(self, x):
#         self.val = x
#         self.left = None
#         self.right = None

class Solution(object):
    def zigzagLevelOrder(self, root):
        """
        :type root: TreeNode
        :rtype: List[List[int]]
        """
        if not root:
            return []
            
        stck=[[root]]
        level=0
        # aleays check the last one
        while len(stck[-1])!=0:
            level+=1
            tmp=[]
            # if the even level
            if not level&1:
                for i in xrange(len(stck[-1])-1,-1,-1):
                    if stck[-1][i].left:
                        tmp.append(stck[-1][i].left)
                    if stck[-1][i].right:
                        tmp.append(stck[-1][i].right)
            # reverse
            else:
                for i in xrange(len(stck[-1])-1,-1,-1):
                    if stck[-1][i].right:
                        tmp.append(stck[-1][i].right)
                    if stck[-1][i].left:
                        tmp.append(stck[-1][i].left)
            stck.append(tmp)
            
        res=[]
        # deal with the stack res
        for i in xrange(len(stck)):
            tmp=[]
            for j in xrange(len(stck[i])):
                tmp.append(stck[i][j].val)
            if tmp:
                res.append(tmp)
        return res
        <commit_msg>[103. Binary Tree Zigzag Level Order Traversal][Accepted]committed by Victor<commit_after># Definition for a binary tree node.
# class TreeNode(object):
#     def __init__(self, x):
#         self.val = x
#         self.left = None
#         self.right = None

class Solution(object):
    def zigzagLevelOrder(self, root):
        """
        :type root: TreeNode
        :rtype: List[List[int]]
        """
        if not root:
            return []
            
        res=[]
        nlevel=0
        level=[root]
        # aleays check the last one
        while level:
            nlevel+=1
            tmp=[]
            vals=[]
            for node in level:
                vals.append(node.val)
                if node.left:
                    tmp.append(node.left)
                if node.right:
                    tmp.append(node.right)
            if nlevel&1:
                res.append(vals)
            else:
                res.append(vals[::-1])
            level=tmp
        return res
        
{'fraction_non_alphanumeric': 0.12053571428571429, 'fraction_numerical': 0.011363636363636364, 'mean_word_length': 1.147212543554007, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3746437', 'n_tokens_mistral': 735, 'n_tokens_neox': 703, 'n_words': 166}