Simple and clear python solution with explain
I use a additional function addLevel to record the level number of nodes, then according to the level number, I can easily deal with the level order, see the co
I use a additional function addLevel to record the level number of nodes, then according to the level number, I can easily deal with the level order, see the code for details\n\n    # Definition for a  binary tree node\n    # class TreeNode:\n    #     def __init__(self, x):\n    #         self.val = x\n    #         self.left = None\n    #         self.right = None\n    \n    class Solution:\n        # @param root, a tree node\n        # @return a list of lists of integers\n        def zigzagLevelOrder(self, root):\n            ans = []\n            self.addLevel(ans, 0, root)#level from 0\n            return ans\n            \n            \n        def addLevel(self, ans, level, root):\n            if not root:\n                return\n            elif len(ans) <= level:\n                    ans.append([root.val])\n            elif not level%2:#if it is an even level, then then level ans should be inversed, so I use extend founction\n                ans[level].extend([root.val])\n            else:\n                ans[level].insert(0,root.val)# if it is an odd level, then level ans should be ordinal, so I use insert function\n            self.addLevel(ans, level + 1, root.left)\n            self.addLevel(ans, level + 1, root.right)
['Python']