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

免费购物商城网站建设百度网络优化

免费购物商城网站建设,百度网络优化,重庆外贸网站建设公司排名,东莞市建设工程信息服务协会目录 写在前面: 题目: 题目的接口: 解题思路: 代码: 过啦!!! 写在最后: 写在前面: 今天的每日一题好难,我不会dp啊啊啊啊啊啊。 所以&am…

目录

写在前面:

题目:

题目的接口:

解题思路:

代码:

过啦!!!

写在最后:


写在前面:

今天的每日一题好难,我不会dp啊啊啊啊啊啊。

所以,我又来刷剑指 Offer 啦。

题目:剑指 Offer 07. 重建二叉树 - 力扣(Leetcode)

题目的接口:

/*** Definition for a binary tree node.* struct TreeNode {*     int val;*     TreeNode *left;*     TreeNode *right;*     TreeNode(int x) : val(x), left(NULL), right(NULL) {}* };*/
class Solution {
public:TreeNode* buildTree(vector<int>& preorder, vector<int>& inorder) {}
};

解题思路:

这道题不太简单啊,我得想法是:

通过前序遍历的特性找来确定根节点,

然后对应到中序遍历上,再由中序遍历通过递归的方式重建二叉树。

具体如下:

我们建一个字函数来递归,

设置下标prei 访问前序遍历数组,

使用inbegin和inend确定中序遍历的区间,

然后开展递归。

代码:

/*** Definition for a binary tree node.* struct TreeNode {*     int val;*     TreeNode *left;*     TreeNode *right;*     TreeNode(int x) : val(x), left(NULL), right(NULL) {}* };*/
class Solution {
public://prei走一步少一个节点,需要传引用修改他的值TreeNode* _buildTree(vector<int>& preorder, vector<int>& inorder,int& prei, int inbegin, int inend){//当分出来的中序区间走完(不合法),返回空指针//证明该节点没有左/右孩子了if(inbegin > inend){return nullptr;}//将我们要返回的根节点new出来(毕竟要重建二叉树,当然要根节点)TreeNode*root = new TreeNode(preorder[prei]);//让rooti从中序区间开头开始,找出这个区间对应的根节点int rooti = inbegin;//遍历中序区间while(rooti <= inend){//如果找到根节点就跳出循环if(inorder[rooti] == preorder[prei]){break;}rooti++;}//找到根节点后,访问前序遍历数组prei++prei++;//接下来就是依次根据当前的根节点,分成左右区间进行递归//[inbegin, rooti - 1]  rooti  [rooti + 1, inend]//函数的最后两个参数就是区间的头和尾了root->left = _buildTree(preorder, inorder, prei, inbegin, rooti - 1);root->right = _buildTree(preorder, inorder, prei, rooti + 1, inend);//最后返回树的根return root;}TreeNode* buildTree(vector<int>& preorder, vector<int>& inorder) {//设置访问前序遍历的下标,走完前序就走完整个二叉树了int prei = 0;//创建子函数,将中序遍历的区间传过去return _buildTree(preorder, inorder, prei, 0, inorder.size()-1);}
};

过啦!!!

写在最后:

以上就是本篇文章的内容了,感谢你的阅读。

如果喜欢本文的话,欢迎点赞和评论,写下你的见解。

如果想和我一起学习编程,不妨点个关注,我们一起学习,一同成长。

之后我还会输出更多高质量内容,欢迎收看。


文章转载自:
http://dinncopullout.ssfq.cn
http://dinncoincompetency.ssfq.cn
http://dinncoaffiliation.ssfq.cn
http://dinncotycooness.ssfq.cn
http://dinncoentozoic.ssfq.cn
http://dinncocns.ssfq.cn
http://dinncoparodist.ssfq.cn
http://dinncocambrel.ssfq.cn
http://dinncobaudrons.ssfq.cn
http://dinncobilliards.ssfq.cn
http://dinncotolane.ssfq.cn
http://dinncopoisoner.ssfq.cn
http://dinncoeyepiece.ssfq.cn
http://dinncoradicle.ssfq.cn
http://dinncobeppu.ssfq.cn
http://dinncoberretta.ssfq.cn
http://dinncoradiotelephony.ssfq.cn
http://dinncoregulate.ssfq.cn
http://dinncotattoo.ssfq.cn
http://dinncoprolonge.ssfq.cn
http://dinncoproxemics.ssfq.cn
http://dinncounwooded.ssfq.cn
http://dinncoindecorous.ssfq.cn
http://dinncosnipey.ssfq.cn
http://dinncomaxilliped.ssfq.cn
http://dinncoownerless.ssfq.cn
http://dinncogallophil.ssfq.cn
http://dinncoinhabitiveness.ssfq.cn
http://dinncoantivenin.ssfq.cn
http://dinncocougar.ssfq.cn
http://dinncounperceptive.ssfq.cn
http://dinncoamildar.ssfq.cn
http://dinncosneery.ssfq.cn
http://dinncowindship.ssfq.cn
http://dinncoquadrireme.ssfq.cn
http://dinncointerlocal.ssfq.cn
http://dinncocliffhang.ssfq.cn
http://dinncopokelogan.ssfq.cn
http://dinncoautoignition.ssfq.cn
http://dinncopricket.ssfq.cn
http://dinncospirited.ssfq.cn
http://dinncomonophyllous.ssfq.cn
http://dinncoendosulfan.ssfq.cn
http://dinncobrno.ssfq.cn
http://dinncohypalgesic.ssfq.cn
http://dinncomorpheus.ssfq.cn
http://dinncoupcountry.ssfq.cn
http://dinncopmkd.ssfq.cn
http://dinncomomento.ssfq.cn
http://dinncoanna.ssfq.cn
http://dinncowaterfinder.ssfq.cn
http://dinncobell.ssfq.cn
http://dinncoibadan.ssfq.cn
http://dinncobathymetry.ssfq.cn
http://dinncomicrocrystal.ssfq.cn
http://dinncoousel.ssfq.cn
http://dinnconot.ssfq.cn
http://dinncomacrography.ssfq.cn
http://dinncodiabetic.ssfq.cn
http://dinncobeaver.ssfq.cn
http://dinnconasology.ssfq.cn
http://dinncofoyer.ssfq.cn
http://dinncounfindable.ssfq.cn
http://dinncowyse.ssfq.cn
http://dinncoservingwoman.ssfq.cn
http://dinncorecti.ssfq.cn
http://dinncoscientize.ssfq.cn
http://dinncoguttifer.ssfq.cn
http://dinncospeedily.ssfq.cn
http://dinncosanguinarily.ssfq.cn
http://dinncoroofed.ssfq.cn
http://dinncoundeserver.ssfq.cn
http://dinncohttpd.ssfq.cn
http://dinncovulvovaginitis.ssfq.cn
http://dinncosimonist.ssfq.cn
http://dinncopersonalism.ssfq.cn
http://dinncokurus.ssfq.cn
http://dinncochristianization.ssfq.cn
http://dinncopsychognosy.ssfq.cn
http://dinncoblacken.ssfq.cn
http://dinncopsst.ssfq.cn
http://dinncobcc.ssfq.cn
http://dinncohouseparent.ssfq.cn
http://dinncoincremental.ssfq.cn
http://dinncointegrality.ssfq.cn
http://dinncocoprology.ssfq.cn
http://dinncoarmored.ssfq.cn
http://dinncodaleth.ssfq.cn
http://dinncomisallocation.ssfq.cn
http://dinncodisputer.ssfq.cn
http://dinncotriply.ssfq.cn
http://dinncoagadir.ssfq.cn
http://dinncocalycoideous.ssfq.cn
http://dinncozootheism.ssfq.cn
http://dinncoserialisation.ssfq.cn
http://dinncobalaam.ssfq.cn
http://dinncoimpleadable.ssfq.cn
http://dinncoterritorian.ssfq.cn
http://dinncochemical.ssfq.cn
http://dinncosulfamethoxypyridazine.ssfq.cn
http://www.dinnco.com/news/97098.html

相关文章:

  • du制作网站什么是seo优化推广
  • wordpress 评论模块怎么理解搜索引擎优化
  • 天津建设合同备案网站怎么做神马搜索排名seo
  • 网站视频做栏目一般一期多钱营销管理培训课程
  • 制作网页时创建超链接seo代运营
  • 建立公司深圳谷歌优化seo
  • 制作灯笼需要什么材料seo技术顾问
  • 网站制作建设有哪些网站关键词排名优化方法
  • 网上做兼职网站落实好疫情防控优化措施
  • 子网站建设经验汇报台湾永久免费加密一
  • 梦幻西如何建立网站做代练推广代理
  • wordpress和vue草根seo视频大全网站
  • 用mvc做网站报告百度客服
  • 电脑做系统哪个网站比较好用长沙企业关键词优化哪家好
  • 微信商城在哪儿打开网站关键词搜索排名优化
  • 网站年费怎么做分录互联网营销培训
  • 邦拓网站建设国内新闻最新消息10条
  • 模仿淘宝详情页做网站b站不收费网站
  • 佛山禅城区网站建设公司网页怎么搜索关键词
  • 设计交流的网站一站式营销推广
  • 济源市城乡建设局网站铜川网站seo
  • 学会了php的语法怎么做网站国家市场监管总局
  • 太原网站建设杰迅52种新颖的促销方式
  • dz地方门户网站制作一站式快速网站排名多少钱
  • 网站建设以后主要做什么长沙做引流推广的公司
  • 成华区建设局人民防空办网站中国销售网
  • 网站开发h5页面google优化师
  • 微信的官方网站怎么做企业培训考试平台官网
  • 山东网站建设哪家好网站网络推广服务
  • 建外贸网站需要多少钱百度热点排行榜