用递归的方法对给定的二叉树进行后序遍历。 例如: 给定的二叉树为{1,#,2,3}, 返回[3,2,1].
示例1
输入
{1,#,2,3}
输出
[3,2,1]
加载中...
import java.util.*; /* * public class TreeNode { * int val = 0; * TreeNode left = null; * TreeNode right = null; * } */ public class Solution { /** * * @param root TreeNode类 * @return int整型ArrayList */ public ArrayList
postorderTraversal (TreeNode root) { // write code here } }
/** * struct TreeNode { * int val; * struct TreeNode *left; * struct TreeNode *right; * }; */ class Solution { public: /** * * @param root TreeNode类 * @return int整型vector */ vector
postorderTraversal(TreeNode* root) { // write code here } };
# class TreeNode: # def __init__(self, x): # self.val = x # self.left = None # self.right = None # # # @param root TreeNode类 # @return int整型一维数组 # class Solution: def postorderTraversal(self , root ): # write code here
/* * function TreeNode(x) { * this.val = x; * this.left = null; * this.right = null; * } */ /** * * @param root TreeNode类 * @return int整型一维数组 */ function postorderTraversal( root ) { // write code here } module.exports = { postorderTraversal : postorderTraversal };
# class TreeNode: # def __init__(self, x): # self.val = x # self.left = None # self.right = None # # # @param root TreeNode类 # @return int整型一维数组 # class Solution: def postorderTraversal(self , root ): # write code here
package main import . "nc_tools" /* * type TreeNode struct { * Val int * Left *TreeNode * Right *TreeNode * } */ /** * * @param root TreeNode类 * @return int整型一维数组 */ func postorderTraversal( root *TreeNode ) []int { // write code here }
{1,#,2,3}
[3,2,1]