public List<List<Integer>> levelOrderBottom2(TreeNode root) {
        List<List<Integer>> result = new ArrayList<List<Integer>>();
        if (root == null) return result;
        List<TreeNode> prev = new ArrayList<TreeNode>();
        List<TreeNode> curr = new ArrayList<TreeNode>();
        List<Integer> level = new ArrayList<Integer>();
        prev.add(root);
        level.add(root.val);
        result.add(level);
        while (!prev.isEmpty()) {
            level = new ArrayList<Integer>();
            for (TreeNode p : prev) {
                if (p.left != null) {
                    curr.add(p.left);
                    level.add(p.left.val);
                }
                if (p.right != null) {
                    curr.add(p.right);
                    level.add(p.right.val);
                }
            }
            if (!level.isEmpty()) result.add(0, level);
            prev = curr;
            curr = new ArrayList<TreeNode>();
        }
        return result;
    }