public HashMap<Integer, ArrayList<Integer>> zigzagLevelHelper(TreeNode root){
        HashMap<Integer, ArrayList<Integer>> res = new HashMap<Integer, ArrayList<Integer>>();
        if(root == null){
            return res;
        }
        
        Queue<TreeNode> q = new LinkedList<TreeNode>();
        Queue<Integer> levelq = new LinkedList<Integer>();
        TreeNode curNode;
        Integer curLevel;
        q.add(root);
        levelq.add(0);
        while(!q.isEmpty()){
            curNode = q.poll();
            curLevel = levelq.poll();
            if(!res.containsKey(curLevel)){
                res.put(curLevel, new ArrayList<Integer>());
                res.get(curLevel).add(curNode.val);
            }
            else{
                if(curLevel%2 == 0){
                	res.get(curLevel).add(curNode.val);
                }
                else{
                	res.get(curLevel).add(0, curNode.val);
                }
            }
            if(curNode.left != null){
                q.add(curNode.left);
                levelq.add(curLevel +1);
            }
            if(curNode.right != null){
                q.add(curNode.right);
                levelq.add(curLevel+1);
            }          
        }
        return res;
    }