public List<List<Integer>> zigzagLevelOrder(TreeNode root) {
        List<List<Integer>> result = new ArrayList<List<Integer>>();
        List<TreeNode> list = new ArrayList<TreeNode>();
        if(root == null)
            return result;
        list.add(root);
        boolean flag =  true;
        while(list.size() != 0){
            List<Integer> intList = new ArrayList<Integer>();
            List<TreeNode> nextList = new ArrayList<TreeNode>();
            for (int i=0;i < list.size() ;i++ ) {
                int index = list.size()-1-i;
                if(flag)
                    index = i;
                TreeNode node = list.get(i);
                intList.add(list.get(index).val);
                if(node.left != null)
                    nextList.add(node.left);
                if(node.right != null)
                    nextList.add(node.right);
            }
            list = nextList;
            result.add(intList);
            flag = !flag;
        }
        return result;
    }