145. Binary Tree Postorder Traversal Easy

@problem@discussion
#Stack#Tree#Depth-First Search#Binary Tree



1/**
2 * [145] Binary Tree Postorder Traversal
3 *
4 * Given the root of a binary tree, return the postorder traversal of its nodes' values.
5 *  
6 * Example 1:
7 * <img alt="" src="https://assets.leetcode.com/uploads/2020/08/28/pre1.jpg" style="width: 127px; height: 200px;" />
8 * Input: root = [1,null,2,3]
9 * Output: [3,2,1]
10 * 
11 * Example 2:
12 * 
13 * Input: root = []
14 * Output: []
15 * 
16 * Example 3:
17 * 
18 * Input: root = [1]
19 * Output: [1]
20 * 
21 *  
22 * Constraints:
23 * 
24 * 	The number of the nodes in the tree is in the range [0, 100].
25 * 	-100 <= Node.val <= 100
26 * 
27 *  
28 * Follow up: Recursive solution is trivial, could you do it iteratively?
29 */
30pub struct Solution {}
31use crate::util::tree::{TreeNode, to_tree};
32
33// problem: https://leetcode.com/problems/binary-tree-postorder-traversal/
34// discuss: https://leetcode.com/problems/binary-tree-postorder-traversal/discuss/?currentPage=1&orderBy=most_votes&query=
35
36// submission codes start here
37
38// Definition for a binary tree node.
39// #[derive(Debug, PartialEq, Eq)]
40// pub struct TreeNode {
41//   pub val: i32,
42//   pub left: Option<Rc<RefCell<TreeNode>>>,
43//   pub right: Option<Rc<RefCell<TreeNode>>>,
44// }
45// 
46// impl TreeNode {
47//   #[inline]
48//   pub fn new(val: i32) -> Self {
49//     TreeNode {
50//       val,
51//       left: None,
52//       right: None
53//     }
54//   }
55// }
56use std::rc::Rc;
57use std::cell::RefCell;
58impl Solution {
59    pub fn postorder_traversal(root: Option<Rc<RefCell<TreeNode>>>) -> Vec<i32> {
60        vec![]
61    }
62}
63
64// submission codes end
65
66#[cfg(test)]
67mod tests {
68    use super::*;
69
70    #[test]
71    fn test_145() {
72    }
73}
74


Back
© 2025 bowen.ge All Rights Reserved.