加载中...
import java.util.*; /** * Definition for binary tree * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */ public class Solution { public TreeNode reConstructBinaryTree(int [] pre,int [] vin) { } }
/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */ class Solution { public: TreeNode* reConstructBinaryTree(vector
pre,vector
vin) { } };
# -*- coding:utf-8 -*- # class TreeNode: # def __init__(self, x): # self.val = x # self.left = None # self.right = None class Solution: # 返回构造的TreeNode根节点 def reConstructBinaryTree(self, pre, vin): # write code here
using System; using System.Collections.Generic; /* public class TreeNode { public int val; public TreeNode left; public TreeNode right; public TreeNode (int x) { val = x; } } */ class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param pre int整型一维数组 * @param tin int整型一维数组 * @return TreeNode类 */ public TreeNode reConstructBinaryTree (List
pre, List
vin) { // write code here } }
/* function TreeNode(x) { this.val = x; this.left = null; this.right = null; } */ function reConstructBinaryTree(pre, vin) { // write code here } module.exports = { reConstructBinaryTree : reConstructBinaryTree };
val = $val; } }*/ /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * @param pre int整型一维数组 * @param vin int整型一维数组 * @return TreeNode类 */ function reConstructBinaryTree( $pre , $vin ) { // write code here }
# class TreeNode: # def __init__(self, x): # self.val = x # self.left = None # self.right = None # # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param pre int整型一维数组 # @param vin int整型一维数组 # @return TreeNode类 # class Solution: def reConstructBinaryTree(self , pre: List[int], vin: List[int]) -> TreeNode: # write code here
package main import . "nc_tools" /* * type TreeNode struct { * Val int * Left *TreeNode * Right *TreeNode * } */ /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * @param pre int整型一维数组 * @param vin int整型一维数组 * @return TreeNode类 */ func reConstructBinaryTree( pre []int , vin []int ) *TreeNode { // write code here }
/** * struct TreeNode { * int val; * struct TreeNode *left; * struct TreeNode *right; * }; */ /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param pre int整型一维数组 * @param preLen int pre数组长度 * @param vin int整型一维数组 * @param vinLen int vin数组长度 * @return TreeNode类 */ struct TreeNode* reConstructBinaryTree(int* pre, int preLen, int* vin, int vinLen ) { // write code here }
# class TreeNode # attr_accessor :val, :left, :right # def initialize(val, left = nil, right = nil) # @val, @left, @right = val, left, right # end # end # # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # @param pre int整型一维数组 # @param vin int整型一维数组 # @return TreeNode类 # class Solution def reConstructBinaryTree(pre, vin) # write code here end end
/** * class TreeNode(var val: Int) { * var left: TreeNode = null * var right: TreeNode = null * } */ object Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * @param pre int整型一维数组 * @param vin int整型一维数组 * @return TreeNode类 */ def reConstructBinaryTree(pre: Array[Int],vin: Array[Int]): TreeNode = { // write code here } }
/** * class TreeNode(var `val`: Int) { * var left: TreeNode? = null * var right: TreeNode? = null * } */ object Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * @param pre int整型一维数组 * @param vin int整型一维数组 * @return TreeNode类 */ fun reConstructBinaryTree(pre: IntArray,vin: IntArray): TreeNode? { // write code here } }
import java.util.*; /* * public class TreeNode { * int val = 0; * TreeNode left = null; * TreeNode right = null; * public TreeNode(int val) { * this.val = val; * } * } */ public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * @param pre int整型一维数组 * @param vin int整型一维数组 * @return TreeNode类 */ public TreeNode reConstructBinaryTree (int[] pre, int[] vin) { // write code here } }
/*class TreeNode { * val: number * left: TreeNode | null * right: TreeNode | null * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) { * this.val = (val===undefined ? 0 : val) * this.left = (left===undefined ? null : left) * this.right = (right===undefined ? null : right) * } * } */ /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * @param pre int整型一维数组 * @param vin int整型一维数组 * @return TreeNode类 */ export function reConstructBinaryTree(pre: number[], vin: number[]): TreeNode { // write code here }
/** * public class TreeNode { * public var val: Int * public var left: TreeNode? * public var right: TreeNode? * public init(_ val: Int=0, _ left: TreeNode?=nil, _ right: TreeNode?=nil) { * self.val = val * self.left = left * self.right = right * } */ public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * @param pre int整型一维数组 * @param vin int整型一维数组 * @return TreeNode类 */ func reConstructBinaryTree ( _ pre: [Int], _ vin: [Int]) -> TreeNode? { // write code here } }
/** * #[derive(PartialEq, Eq, Debug, Clone)] * pub struct TreeNode { * pub val: i32, * pub left: Option
>, * pub right: Option
>, * } * * impl TreeNode { * #[inline] * fn new(val: i32) -> Self { * TreeNode { * val: val, * left: None, * right: None, * } * } * } */ struct Solution{ } impl Solution { fn new() -> Self { Solution{} } /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * @param pre int整型一维数组 * @param vin int整型一维数组 * @return TreeNode类 */ pub fn reConstructBinaryTree(&self, pre: Vec
, vin: Vec
) -> Option
> { // write code here } }
[1,2,4,7,3,5,6,8],[4,7,2,1,5,3,8,6]
{1,2,3,4,#,5,6,#,7,#,#,8}
[1],[1]
{1}
[1,2,3,4,5,6,7],[3,2,4,1,6,5,7]
{1,2,5,3,4,6,7}