class Solution {
public List<List<Integer>> zigzagLevelOrder(TreeNode root) {
List<List<Integer>> lists = new ArrayList<>();
zigzagLevelOrderDFS(root, lists, 0);
return lists;
}
private void zigzagLevelOrderDFS(TreeNode root, List<List<Integer>> lists, int deep) {
if (root == null) return;
if (lists.size() == deep) lists.add(new LinkedList<>());
if (deep % 2 == 0) lists.get(deep).add(root.val);
else lists.get(deep).add(0, root.val);
zigzagLevelOrderDFS(root.left, lists, ++deep);
zigzagLevelOrderDFS(root.right, lists, deep);
}
}