public List<List<Integer>> zigzagLevelOrder(TreeNode root) {
        List<List<Integer>> result = new ArrayList<>();
        if (root == null)
            return result;

        Queue<TreeNode> queue = new LinkedList<>();
        queue.add(root);
        int currentLevel = 1;
        int nextLevel = 0;
        int levelCounter = 0;
        List<Integer> tempList = new ArrayList<>();

        while (!queue.isEmpty()) {
            TreeNode t = queue.remove();
            currentLevel = currentLevel - 1;
            tempList.add(t.val);
            if (t.left != null) {
                queue.add(t.left);
                nextLevel = nextLevel + 1;
            }
            if (t.right != null) {
                queue.add(t.right);
                nextLevel = nextLevel + 1;
            }
            if (currentLevel == 0) {
                currentLevel = nextLevel;
                nextLevel = 0;
                if (levelCounter % 2 == 0) {
                    result.add(tempList);
                } else {
                    Collections.reverse(tempList);
                    result.add(tempList);
                }
                tempList = new ArrayList<>();
                levelCounter = levelCounter + 1;
            }
        }
        return result;
    }