classSolution{publicList<Integer>postorderTraversal(TreeNoderoot){LinkedList<Integer>list=newLinkedList<>();if(root==null){returnlist;}LinkedList<TreeNode>stack=newStack<>();stack.push(root);while(!stack.isEmpty()){//后序遍历 left right root//root right leftTreeNodenode=stack.pop();list.addFirst(node.val);if(node.left!=null){stack.push(node.left);}if(node.right!=null){stack.push(node.right);}}returnlist;}}