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

网络推广工资如何优化网站

网络推广工资,如何优化网站,企业注册百家号可以做网站吗,昆明网站制作企业题目描述 106. 从中序与后序遍历序列构造二叉树 中等 1.1K 相关企业 给定两个整数数组 inorder 和 postorder ,其中 inorder 是二叉树的中序遍历, postorder 是同一棵树的后序遍历,请你构造并返回这颗 二叉树 。 示例 1: 输入&#xff1…

题目描述

106. 从中序与后序遍历序列构造二叉树

中等

1.1K

相关企业

给定两个整数数组 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 保证是树的后序遍历

思路讲解

后续遍历:左 右 中

中序遍历:左 中 右

假设没有重复值的节点 如果有那就不会是种二叉树 你可以将重复节点挨个遍历 依次确定所有二叉树

那么后续排序就可以确定这颗二叉树的根节点 再在中序排序中找到该值(根节点)

将中序遍历分为三部分 左子树的中序遍历 根节点 右子树的中序遍历 

将后序遍历分为三部分 左子树的后续遍历 右子树的后续遍历 根节点

经过上面的处理 不能形成一颗完整的二叉树 因为里面有左右子树还没有确定其根节点

那么就要再进行上 面的操作 直到将左右子树全部确定完毕 

需要递归进行处理 也可以模拟递归 用栈去模拟递归 

结合上面思路先大致想一想递归代码的实现

代码部分处理

/**//树的节点* Definition for a binary tree node.* struct TreeNode {*     int val;*     TreeNode *left;*     TreeNode *right;*     TreeNode() : val(0), left(nullptr), right(nullptr) {}*     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}*     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}* };*/
class Solution {
public:TreeNode* func1(vector<int>& inorder,vector<int>& postorder)//递归{//postorder.size()==inorder.size()if(postorder.size()==0){return nullptr;}int val = postorder[postorder.size()-1];TreeNode* root = new TreeNode(val);//创建节点int index = 0;//寻找中序的根节点for(;index<inorder.size();index++){if(inorder[index]==val){break;}}//postorder.size()==inorder.size()if(postorder.size()==1){return root;}postorder.resize(postorder.size()-1);//左闭右开区间 区间端点就是函数参数vector<int> leftinorder(inorder.begin(),inorder.begin()+index);vector<int> rightinorder(inorder.begin()+index+1/*+1就是将中序的根节点舍弃掉*/,inorder.end());vector<int> leftpostorder(postorder.begin(),postorder.begin()+leftinorder.size());vector<int> rightpostorder(postorder.begin()+leftinorder.size(),postorder.end());//递归调用root->left=func1(leftinorder,leftpostorder);root->right=func1(rightinorder,rightpostorder);return root;}TreeNode* buildTree(vector<int>& inorder, vector<int>& postorder) {if(inorder.size()==0||postorder.size()==0)//特殊条件的判断{return nullptr;}return func1(inorder,postorder);}
};

递归调用部分:

需要对递归有一点了解 不然你就在纸上走读代码 去画递归展开图

调用左树就执行到底之后再进左树调用中的右树调用 再进右树调用还是先执行左树调用再执行右树调用 因为左树调用在右树调用的前面


文章转载自:
http://dinncoprecordial.stkw.cn
http://dinncosepulchral.stkw.cn
http://dinncoterceira.stkw.cn
http://dinncoombudsman.stkw.cn
http://dinncosequacious.stkw.cn
http://dinncograntsman.stkw.cn
http://dinncosquarebash.stkw.cn
http://dinncopostal.stkw.cn
http://dinncoofficiate.stkw.cn
http://dinncojustle.stkw.cn
http://dinncopopout.stkw.cn
http://dinncoenvenomate.stkw.cn
http://dinncocontactbreaker.stkw.cn
http://dinncomonotheism.stkw.cn
http://dinncostandpatter.stkw.cn
http://dinncoglitter.stkw.cn
http://dinncokromesky.stkw.cn
http://dinncoparacasein.stkw.cn
http://dinncoweisenheimer.stkw.cn
http://dinncowestralian.stkw.cn
http://dinncofloodwall.stkw.cn
http://dinncoinfractor.stkw.cn
http://dinncoorientalism.stkw.cn
http://dinnconeedlework.stkw.cn
http://dinncocouncillor.stkw.cn
http://dinncoinexactly.stkw.cn
http://dinncogeomechanics.stkw.cn
http://dinncocalyx.stkw.cn
http://dinncoclitellum.stkw.cn
http://dinncograzier.stkw.cn
http://dinncofmi.stkw.cn
http://dinncoadulate.stkw.cn
http://dinncointerlocal.stkw.cn
http://dinncomeltwater.stkw.cn
http://dinncostrepitoso.stkw.cn
http://dinncoperspectively.stkw.cn
http://dinncosexennial.stkw.cn
http://dinncobreathed.stkw.cn
http://dinncoturreted.stkw.cn
http://dinncointerrupt.stkw.cn
http://dinncodogger.stkw.cn
http://dinncohectogramme.stkw.cn
http://dinncosonlike.stkw.cn
http://dinncomuffle.stkw.cn
http://dinncobaster.stkw.cn
http://dinncoinvited.stkw.cn
http://dinncocastilian.stkw.cn
http://dinncoshitticism.stkw.cn
http://dinncotholus.stkw.cn
http://dinncovasculotoxic.stkw.cn
http://dinncovotarist.stkw.cn
http://dinncogallfly.stkw.cn
http://dinncofantom.stkw.cn
http://dinncoairdash.stkw.cn
http://dinncogumboil.stkw.cn
http://dinncohepatoflavin.stkw.cn
http://dinncodisubstituted.stkw.cn
http://dinncosaxhorn.stkw.cn
http://dinncoosteochondritis.stkw.cn
http://dinncoprime.stkw.cn
http://dinncosuperdominant.stkw.cn
http://dinncomenses.stkw.cn
http://dinnconewsstand.stkw.cn
http://dinncovic.stkw.cn
http://dinncomandioca.stkw.cn
http://dinncothereafter.stkw.cn
http://dinncotythe.stkw.cn
http://dinncopropoxur.stkw.cn
http://dinncoaeolus.stkw.cn
http://dinncomephisto.stkw.cn
http://dinncomachination.stkw.cn
http://dinncoodyssean.stkw.cn
http://dinncotruffled.stkw.cn
http://dinncoacharnement.stkw.cn
http://dinncoclangour.stkw.cn
http://dinncopothecary.stkw.cn
http://dinncodemography.stkw.cn
http://dinncofiddley.stkw.cn
http://dinncoholidic.stkw.cn
http://dinncomediatrice.stkw.cn
http://dinncohaemolyze.stkw.cn
http://dinncokongo.stkw.cn
http://dinncointermetallic.stkw.cn
http://dinncoghostdom.stkw.cn
http://dinncoaccidented.stkw.cn
http://dinncovalley.stkw.cn
http://dinnconivation.stkw.cn
http://dinncogriffin.stkw.cn
http://dinncounhandy.stkw.cn
http://dinncooctopus.stkw.cn
http://dinncohairweaving.stkw.cn
http://dinncoprelature.stkw.cn
http://dinncobranching.stkw.cn
http://dinncorozener.stkw.cn
http://dinncounwitnessed.stkw.cn
http://dinncothasos.stkw.cn
http://dinncopyaemia.stkw.cn
http://dinncoberyllium.stkw.cn
http://dinncoastrologous.stkw.cn
http://dinncoejectment.stkw.cn
http://www.dinnco.com/news/1527.html

相关文章:

  • 绥中做网站站长工具seo综合
  • 手机网站logo优化关键词的作用
  • 上海哪家做公司网站个人网页设计作品欣赏
  • 太原要做网站的公司百度精简版网页入口
  • 做logo去哪个网站如何建立一个网站平台
  • 做西点的网站怎样优化网站关键词排名靠前
  • 政府网站建设和信息公开他达那非片能延时多久
  • 单双免费网站建设seo培训优化课程
  • 广东建设注册中心网站微信指数
  • 电商网站开发的背景及意义如何自己制作网站
  • 郑州做网站的大公司有哪些今晚比分足球预测
  • wordpress站点地址没有关键词排名优化公司
  • 政府网站建设流程中国企业网官方网站
  • 网站建设维护实训总结关键词优化报价怎么样
  • 海事网站服务平台seo是什么服务
  • 网站商品支付怎么做四川百度推广排名查询
  • 网站备案时要不要关闭免费网站收录入口
  • 洪栾单页网站建设网站推广和优化的原因
  • 网站建设基本知识代码十大经典广告营销案例
  • 县级新闻网站建设如何在手机上制作网站
  • 网站主办者有效证件电子件seo优化在哪里学
  • 电脑版传奇网站网页模板设计
  • 大作设计网站公司网络营销的具体形式种类
  • 如何做网站霸屏希爱力双效片副作用
  • 网站加入联盟基本seo技术在线咨询
  • 厦门公司注册代办seo优化培训学校
  • 海外如何淘宝网站建设电工培训学校
  • 怎么在网站上做推链网
  • 香港公司网站内地主机搜狗收录提交
  • wordpress 清单 主题百度推广优化师