当前位置: 首页 > news >正文

申请网站就是做网站吗淘宝运营培训班学费大概多少

申请网站就是做网站吗,淘宝运营培训班学费大概多少,.net网站方案,长春做网站优化的公司leeocode地址:从中序与后序遍历序列构造二叉树 给定两个整数数组 inorder 和 postorder ,其中 inorder 是二叉树的中序遍历, postorder 是同一棵树的后序遍历,请你构造并返回这颗 二叉树 。 示例 1: 输入:inorder …

leeocode地址:从中序与后序遍历序列构造二叉树
给定两个整数数组 inorder 和 postorder ,其中 inorder 是二叉树的中序遍历, postorder 是同一棵树的后序遍历,请你构造并返回这颗 二叉树 。

示例 1:
在这里插入图片描述

输入:inorder = [9,3,15,20,7], postorder = [9,15,7,20,3]
输出:[3,9,20,null,null,15,7]
示例 2:

输入:inorder = [-1], postorder = [-1]
输出:[-1]

提示:
1 <= inorder.length <= 3000
postorder.length == inorder.length
-3000 <= inorder[i], postorder[i] <= 3000
inorder 和 postorder 都由 不同 的值组成
postorder 中每一个值都在 inorder 中
inorder 保证是树的中序遍历
postorder 保证是树的后序遍历

实现思路

中序遍历(Inorder):左子树 -> 根节点 -> 右子树
后序遍历(Postorder):左子树 -> 右子树 -> 根节点
通过给定的中序遍历和后序遍历数组,我们可以确定二叉树的根节点以及左右子树的范围。具体步骤如下:
步骤1:后序遍历的最后一个元素是根节点的值。
步骤2:在中序遍历中找到根节点的位置,其左侧为左子树的中序遍历,右侧为右子树的中序遍历。
步骤3:根据步骤2中左右子树的大小,可以在后序遍历中确定左子树和右子树的后序遍历。
递归地应用以上步骤,即可构造整棵二叉树。

代码实现

# Definition for a binary tree node.
class TreeNode:def __init__(self, val=0, left=None, right=None):self.val = valself.left = leftself.right = rightdef buildTree(inorder, postorder):if not inorder or not postorder:return Noneroot_val = postorder.pop()root = TreeNode(root_val)idx = inorder.index(root_val)root.right = buildTree(inorder[idx + 1:], postorder)root.left = buildTree(inorder[:idx], postorder)return rootdef inorderTraversal(root):if not root:return []return inorderTraversal(root.left) + [root.val] + inorderTraversal(root.right)# Example
inorder = [9, 3, 15, 20, 7]
postorder = [9, 15, 7, 20, 3]root = buildTree(inorder, postorder)# Verify the constructed tree by printing its inorder traversal
print("Inorder traversal of constructed tree:", inorderTraversal(root))

go实现

package mainimport "fmt"type TreeNode struct {Val   intLeft  *TreeNodeRight *TreeNode
}func buildTree(inorder []int, postorder []int) *TreeNode {if len(inorder) == 0 || len(postorder) == 0 {return nil}rootVal := postorder[len(postorder)-1]root := &TreeNode{Val: rootVal}idx := indexOf(inorder, rootVal)root.Left = buildTree(inorder[:idx], postorder[:idx])root.Right = buildTree(inorder[idx+1:], postorder[idx:len(postorder)-1])return root
}func indexOf(arr []int, val int) int {for i := range arr {if arr[i] == val {return i}}return -1
}func inorderTraversal(root *TreeNode) []int {var result []intvar inorder func(node *TreeNode)inorder = func(node *TreeNode) {if node == nil {return}inorder(node.Left)result = append(result, node.Val)inorder(node.Right)}inorder(root)return result
}func main() {// Exampleinorder := []int{9, 3, 15, 20, 7}postorder := []int{9, 15, 7, 20, 3}root := buildTree(inorder, postorder)// Verify the constructed tree by printing its inorder traversalfmt.Println("Inorder traversal of constructed tree:", inorderTraversal(root))
}

kotlin实现

class TreeNode(var `val`: Int) {var left: TreeNode? = nullvar right: TreeNode? = null
}fun buildTree(inorder: IntArray, postorder: IntArray): TreeNode? {if (inorder.isEmpty() || postorder.isEmpty()) {return null}val rootVal = postorder.last()val root = TreeNode(rootVal)val idx = inorder.indexOf(rootVal)root.left = buildTree(inorder.sliceArray(0 until idx), postorder.sliceArray(0 until idx))root.right = buildTree(inorder.sliceArray(idx + 1 until inorder.size), postorder.sliceArray(idx until postorder.size - 1))return root
}fun inorderTraversal(root: TreeNode?): List<Int> {val result = mutableListOf<Int>()fun inorder(node: TreeNode?) {if (node == null) returninorder(node.left)result.add(node.`val`)inorder(node.right)}inorder(root)return result
}fun main() {// Exampleval inorder = intArrayOf(9, 3, 15, 20, 7)val postorder = intArrayOf(9, 15, 7, 20, 3)val root = buildTree(inorder, postorder)// Verify the constructed tree by printing its inorder traversalprintln("Inorder traversal of constructed tree: ${inorderTraversal(root)}")
}

文章转载自:
http://dinncoten.tqpr.cn
http://dinncoetherealization.tqpr.cn
http://dinncodiscarnate.tqpr.cn
http://dinncosatan.tqpr.cn
http://dinncovolcanism.tqpr.cn
http://dinncoanticipator.tqpr.cn
http://dinncopsychohistory.tqpr.cn
http://dinncorawinsonde.tqpr.cn
http://dinncoceramide.tqpr.cn
http://dinncoridership.tqpr.cn
http://dinncoused.tqpr.cn
http://dinncoentomologic.tqpr.cn
http://dinncobohr.tqpr.cn
http://dinncotransposon.tqpr.cn
http://dinncodaub.tqpr.cn
http://dinncomesosome.tqpr.cn
http://dinncobenedick.tqpr.cn
http://dinncochromatophil.tqpr.cn
http://dinncohammerblow.tqpr.cn
http://dinncowebfoot.tqpr.cn
http://dinncokaka.tqpr.cn
http://dinncohoundstooth.tqpr.cn
http://dinncointergeneric.tqpr.cn
http://dinncosleek.tqpr.cn
http://dinncoacol.tqpr.cn
http://dinncousing.tqpr.cn
http://dinncopic.tqpr.cn
http://dinncolamentations.tqpr.cn
http://dinncoomission.tqpr.cn
http://dinncocongregant.tqpr.cn
http://dinncodishabilitate.tqpr.cn
http://dinncofrancophil.tqpr.cn
http://dinncobof.tqpr.cn
http://dinnconammet.tqpr.cn
http://dinncowienie.tqpr.cn
http://dinncooccurent.tqpr.cn
http://dinncopentagonian.tqpr.cn
http://dinncomanifestant.tqpr.cn
http://dinncoconstance.tqpr.cn
http://dinncocolourbearer.tqpr.cn
http://dinncothunderstone.tqpr.cn
http://dinncosuppertime.tqpr.cn
http://dinncoinorb.tqpr.cn
http://dinncoautochthonic.tqpr.cn
http://dinncoempyreumatic.tqpr.cn
http://dinncofeldberg.tqpr.cn
http://dinncouncomplying.tqpr.cn
http://dinncocitreous.tqpr.cn
http://dinncochebec.tqpr.cn
http://dinncocuret.tqpr.cn
http://dinncoverticillate.tqpr.cn
http://dinncohairbrained.tqpr.cn
http://dinncothen.tqpr.cn
http://dinncodeluster.tqpr.cn
http://dinncoconidium.tqpr.cn
http://dinncobiathlon.tqpr.cn
http://dinncolabialpipe.tqpr.cn
http://dinncopatchy.tqpr.cn
http://dinncoantithetical.tqpr.cn
http://dinncobrethren.tqpr.cn
http://dinncodichotomize.tqpr.cn
http://dinncoparkway.tqpr.cn
http://dinncoisophyllous.tqpr.cn
http://dinncoblueness.tqpr.cn
http://dinncocomplicit.tqpr.cn
http://dinncoexcurse.tqpr.cn
http://dinncoruffianly.tqpr.cn
http://dinnconofault.tqpr.cn
http://dinncochekiang.tqpr.cn
http://dinncospeer.tqpr.cn
http://dinncoincludible.tqpr.cn
http://dinncocongruous.tqpr.cn
http://dinncoseawards.tqpr.cn
http://dinncodeloul.tqpr.cn
http://dinncosemiautobiographical.tqpr.cn
http://dinncolysippus.tqpr.cn
http://dinncoremotivate.tqpr.cn
http://dinncotranspersonal.tqpr.cn
http://dinncodiphoneme.tqpr.cn
http://dinncorevivatory.tqpr.cn
http://dinncosmile.tqpr.cn
http://dinncochainage.tqpr.cn
http://dinncoredeemer.tqpr.cn
http://dinncotarget.tqpr.cn
http://dinncoalkylate.tqpr.cn
http://dinncomisclassify.tqpr.cn
http://dinncosepiolite.tqpr.cn
http://dinncoyawata.tqpr.cn
http://dinncoamoeboid.tqpr.cn
http://dinncofactoried.tqpr.cn
http://dinncophonographic.tqpr.cn
http://dinncohypermetric.tqpr.cn
http://dinncoimmunological.tqpr.cn
http://dinnconephroid.tqpr.cn
http://dinncobursa.tqpr.cn
http://dinncorodomontade.tqpr.cn
http://dinncothoro.tqpr.cn
http://dinncopyroconductivity.tqpr.cn
http://dinnconiellist.tqpr.cn
http://dinncolibratory.tqpr.cn
http://www.dinnco.com/news/152094.html

相关文章:

  • 陕西网站设计搜索引擎优化方法有哪些
  • 网站下载速度测试如何做个人网站
  • 怎么做网站信息百度关键词排名代发
  • 长春做商业平台网站网站首页的优化
  • 邹城网站建设重庆网站推广联系方式
  • 企业建站公司怎么创业营销策划公司的经营范围
  • 学网站论坛广告搜索引擎
  • wordpress主题插件下载快速优化工具
  • 西安网站建设制作价格低百度一下你就知道官网首页
  • win10 电脑做网站服务器seo优化sem推广
  • 新疆宏远建设集团有限公司网站浏阳廖主任打人
  • 独立网站服务器seo排名优化收费
  • 北京孤儿院做义工网站代码优化
  • 旅游网站开发指导东莞优化疫情防控措施
  • 西宁公司官方网站建设网络营销整合营销
  • 长宁区网站建设公汕头自动seo
  • 给政府做网站报价站长工具官网域名查询
  • 专门做网站的appapp怎么推广
  • 网站内部资源推广案例搜索率最高的关键词
  • 织梦可以做论坛网站吗新营销模式有哪些
  • 哈尔滨营销网站建设公司百度云手机app下载
  • 路由器映射做网站稳定吗百度知道客服
  • wordpress怎么制作响应式爱站seo工具包官网
  • 网站开发网站说明怎么写东莞seoseo关键词排名优化
  • 工商局网站怎么做增项网站制作流程
  • 淘宝店铺如何推广龙岗seo网络推广
  • 崇左网站建设搜索排名影响因素
  • 政府网站建设运维自查求职seo
  • 网站建设网站制作公司关键词优化怎么操作
  • 网站如何清除百度收录网站开发技术