给定一个先序遍历与中序遍历的二叉树,要求求出该二叉树的后序遍历表示形式。对于如下二叉树: 其先序遍历为:GDAFEMHZ 其中序遍历为:ADEFGHMZ 当给定先序遍历与中序遍历时,该二叉树就被唯一的确定下来,这时即可求出二叉树的后序表示为:AEFDHZMG。 给定输入中,二叉树中的字符有且仅有一个,且二叉树中的所有节点互不相同 输入: 两行,第一行为二叉树的先序遍历表示,第二行为二叉树的中序遍历表示 输出: 一行,二叉树的后续遍历表示
示例1
输入
"GDAFEMHZ","ADEFGHMZ"
输出
"AEFDHZMG"
加载中...
import java.util.*; public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param preStr string字符串 * @param midStr string字符串 * @return string字符串 */ public String binaryTree (String preStr, String midStr) { // write code here } }
class Solution { public: /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param preStr string字符串 * @param midStr string字符串 * @return string字符串 */ string binaryTree(string preStr, string midStr) { // write code here } };
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param preStr string字符串 # @param midStr string字符串 # @return string字符串 # class Solution: def binaryTree(self , preStr , midStr ): # write code here
using System; using System.Collections.Generic; class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param preStr string字符串 * @param midStr string字符串 * @return string字符串 */ public string binaryTree (string preStr, string midStr) { // write code here } }
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param preStr string字符串 * @param midStr string字符串 * @return string字符串 */ function binaryTree( preStr , midStr ) { // write code here } module.exports = { binaryTree : binaryTree };
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param preStr string字符串 # @param midStr string字符串 # @return string字符串 # class Solution: def binaryTree(self , preStr , midStr ): # write code here
package main /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param preStr string字符串 * @param midStr string字符串 * @return string字符串 */ func binaryTree( preStr string , midStr string ) string { // write code here }
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param preStr string字符串 * @param midStr string字符串 * @return string字符串 */ char* binaryTree(char* preStr, char* midStr ) { // write code here }
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param preStr string字符串 # @param midStr string字符串 # @return string字符串 # class Solution def binaryTree(preStr, midStr) # write code here end end
object Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param preStr string字符串 * @param midStr string字符串 * @return string字符串 */ def binaryTree(preStr: String,midStr: String): String = { // write code here } }
object Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param preStr string字符串 * @param midStr string字符串 * @return string字符串 */ fun binaryTree(preStr: String,midStr: String): String { // write code here } }
import java.util.*; public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param preStr string字符串 * @param midStr string字符串 * @return string字符串 */ public String binaryTree (String preStr, String midStr) { // write code here } }
"GDAFEMHZ","ADEFGHMZ"
"AEFDHZMG"