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

        Queue<TreeNode> q1 = new LinkedList<>();
        Queue<TreeNode> q2 = new LinkedList<>();
        q1.offer(root);

        while (!q1.isEmpty() || !q2.isEmpty()) {
            List<Integer> tmp = new ArrayList<>();
            Queue<TreeNode> noEmptyQ = q1.isEmpty()? q2 :q1;
            Queue<TreeNode> emptyQ =   q1.isEmpty()? q1 :q2;

            while (!noEmptyQ.isEmpty()){
                TreeNode cur = noEmptyQ.poll();
                tmp.add(cur.val);
                if (cur.left != null)
                    emptyQ.offer(cur.left);
                if (cur.right != null)
                    emptyQ.offer(cur.right);
            }
            stack.push(tmp);
        }
        while (!stack.isEmpty())
            result.add(stack.pop());
        return result;
    }