@@ -0,0 +1,2137 @@
+package leetcode;%0A%0Aimport java.util.ArrayList;%0Aimport java.util.Collections;%0Aimport java.util.HashMap;%0Aimport java.util.LinkedList;%0Aimport java.util.List;%0Aimport java.util.Map;%0Aimport java.util.Queue;%0A%0A/**%0A * https://leetcode.com/problems/binary-tree-zigzag-level-order-traversal/%0A */%0Apublic class Problem103 %7B%0A    public static class TreeNode %7B%0A        int val;%0A        TreeNode left;%0A        TreeNode right;%0A%0A        TreeNode(int x) %7B%0A            val = x;%0A        %7D%0A    %7D%0A%0A    public List%3CList%3CInteger%3E%3E zigzagLevelOrder(TreeNode root) %7B%0A        List%3CList%3CInteger%3E%3E result = new ArrayList%3C%3E();%0A        if (root == null) %7B%0A            return result;%0A        %7D%0A        Map%3CInteger, List%3CInteger%3E%3E map = new HashMap%3C%3E();%0A        Queue%3CLevelTreeNode%3E queue = new LinkedList%3C%3E();%0A        queue.add(new LevelTreeNode(1, root));%0A        while (!queue.isEmpty()) %7B%0A            LevelTreeNode ltn = queue.remove();%0A            if (!map.containsKey(ltn.level)) %7B%0A                List%3CInteger%3E list = new ArrayList%3C%3E();%0A                list.add(ltn.node.val);%0A                map.put(ltn.level, list);%0A            %7D else %7B%0A                map.get(ltn.level).add(ltn.node.val);%0A            %7D%0A            if (ltn.node.left != null) %7B%0A                queue.add(new LevelTreeNode(ltn.level+1, ltn.node.left));%0A            %7D%0A            if (ltn.node.right != null) %7B%0A                queue.add(new LevelTreeNode(ltn.level+1, ltn.node.right));%0A            %7D%0A        %7D%0A        boolean leftToRight = true;%0A        for (int i = 1; i %3C= map.size(); i++) %7B%0A            if (leftToRight) %7B%0A                result.add(map.get(i));%0A                leftToRight = false;%0A            %7D else %7B%0A                List%3CInteger%3E list = map.get(i);%0A                Collections.reverse(list);%0A                result.add(list);%0A                leftToRight = true;%0A            %7D%0A        %7D%0A        return result;%0A    %7D%0A%0A    private static class LevelTreeNode %7B%0A        private final int level;%0A        private final TreeNode node;%0A        %0A        public LevelTreeNode(int level, TreeNode node) %7B%0A            this.level = level;%0A            this.node = node;%0A        %7D%0A    %7D%0A%7D%0A

Solve problem 103