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

免费微网站怎么做龙岗百度快速排名

免费微网站怎么做,龙岗百度快速排名,在网站文章锚文本怎么做,网站建设demo欢迎浏览高耳机的博客 希望我们彼此都有更好的收获 感谢三连支持! 首先,根据先序遍历可以确定根节点E,再在中序遍历中通过E确定左树和右数 ; 设立inBegin和inEnd,通过这两个参数的游走,来进行子树的创建&a…

欢迎浏览高耳机的博客

希望我们彼此都有更好的收获

感谢三连支持!

 

首先,根据先序遍历可以确定根节点E,再在中序遍历中通过E确定左树和右数 ;

设立inBegin和inEnd,通过这两个参数的游走,来进行子树的创建;

已知根节点,则左子树的范围表示为(inBegin,rootIndex - 1);

而右子树为(rootIndex + 1,inEnd);

通过递归调用,即可不断创建子树,直到叶子节点;

如果inBegin > inEnd,则说明此时为叶子节点,应该返回上一层递归;

public TreeNode buildTree(int[] preorder, int[] inorder) {return buildTreeChilde(preorder, inorder, 0, inorder.length-1);
}private TreeNode buildTreeChilde(int[] preorder, int[] inorder, int inBegin, int inEnd) {if(inBegin > inEnd){return null;}TreeNode root = new TreeNode(preorder[preIndex]); // 创建根节点int rootIndex = findRootIndex(inorder, inBegin, inEnd, preorder[preIndex]); // 找到根节点在中序遍历中的位置preIndex++;root.left = buildTreeChilde(preorder, inorder, inBegin, rootIndex-1); // 递归构建左子树root.right = buildTreeChilde(preorder, inorder, rootIndex+1, inEnd); // 递归构建右子树return root;
}private int findRootIndex(int[] inorder, int inBegin, int inEnd, int key){for (int i = inBegin; i <= inEnd; i++) {if (key == inorder[i]) {return i;}}return -1;}

OJ链接:

https://leetcode.cn/problems/construct-binary-tree-from-preorder-and-inorder-traversal/description/

 

同样的,根据后序遍历可以确定根节点,再在中序遍历中通过根节点确定左树和右数 ;

需要注意的是,由于postIndex根据后序遍历(左,右,根)创建,与前序遍历相反,所以每次递归时postIndex--,从根节点前的右子树开始递归;

同样的,已知根节点,则右子树表示范围为(rootIndex + 1,inEnd);

而左子树表示为(inBegin,rootIndex - 1);

通过递归调用,即可不断创建子树,直到叶子节点;

如果inBegin > inEnd,则说明此时为叶子节点,应该返回上一层递归;

 

public TreeNode buildTree(int[] inorder, int[] postorder) {postIndex = postorder.length-1;return buildTreeChilde(inorder, postorder, 0, inorder.length-1);
}private TreeNode buildTreeChilde(int[] inorder, int[] postorder, int inBegin, int inEnd) {if(inBegin > inEnd){return null;}TreeNode root = new TreeNode(postorder[postIndex]); // 创建根节点int rootIndex = findRootIndex(inorder, inBegin, inEnd, postorder[postIndex]); // 找到根节点在中序遍历中的位置postIndex--;root.right = buildTreeChilde(inorder, postorder, rootIndex+1, inEnd); // 递归构建右子树root.left = buildTreeChilde(inorder, postorder, inBegin, rootIndex-1); // 递归构建左子树return root;
}private int findRootIndex(int[] inorder, int inBegin, int inEnd, int key){for (int i = inBegin; i <= inEnd; i++) {if (key == inorder[i]) {return i;}}return -1;}

OJ链接:https://leetcode.cn/problems/construct-binary-tree-from-inorder-and-postorder-traversal/description/ 


希望这篇博客能为你理解java编程思想提供一些帮助。

如有不足之处请多多指出。

我是高耳机。 


文章转载自:
http://athene.c7507.cn
http://recurrence.c7507.cn
http://gate.c7507.cn
http://yestereve.c7507.cn
http://probationer.c7507.cn
http://bathurst.c7507.cn
http://voussoir.c7507.cn
http://unworkable.c7507.cn
http://appetite.c7507.cn
http://vidicon.c7507.cn
http://yanam.c7507.cn
http://operationalize.c7507.cn
http://allimportant.c7507.cn
http://palatable.c7507.cn
http://brominate.c7507.cn
http://employe.c7507.cn
http://cage.c7507.cn
http://bidarkee.c7507.cn
http://toby.c7507.cn
http://intuc.c7507.cn
http://grant.c7507.cn
http://wirescape.c7507.cn
http://nbf.c7507.cn
http://merlon.c7507.cn
http://nordic.c7507.cn
http://schoolgirl.c7507.cn
http://choush.c7507.cn
http://arrenotokous.c7507.cn
http://australasia.c7507.cn
http://citizeness.c7507.cn
http://isocyanate.c7507.cn
http://machining.c7507.cn
http://heartburning.c7507.cn
http://mis.c7507.cn
http://homoplasy.c7507.cn
http://rhyton.c7507.cn
http://regurgitant.c7507.cn
http://manslaughter.c7507.cn
http://unsteady.c7507.cn
http://lockpick.c7507.cn
http://scissorsbird.c7507.cn
http://posnet.c7507.cn
http://vagarious.c7507.cn
http://gibberellin.c7507.cn
http://bushwhack.c7507.cn
http://dite.c7507.cn
http://noser.c7507.cn
http://shelterless.c7507.cn
http://viewdata.c7507.cn
http://yanqui.c7507.cn
http://spoondrift.c7507.cn
http://canty.c7507.cn
http://phylactery.c7507.cn
http://honourably.c7507.cn
http://samisen.c7507.cn
http://continuum.c7507.cn
http://bordetela.c7507.cn
http://dinghy.c7507.cn
http://aestival.c7507.cn
http://adi.c7507.cn
http://coronavirus.c7507.cn
http://planarian.c7507.cn
http://gluey.c7507.cn
http://plosion.c7507.cn
http://thrace.c7507.cn
http://marriageable.c7507.cn
http://dholl.c7507.cn
http://semple.c7507.cn
http://victimless.c7507.cn
http://ambassadorial.c7507.cn
http://quatercentenary.c7507.cn
http://anticatarrhal.c7507.cn
http://salivary.c7507.cn
http://cliffside.c7507.cn
http://contrivance.c7507.cn
http://pessimistic.c7507.cn
http://acouasm.c7507.cn
http://spittoon.c7507.cn
http://beaked.c7507.cn
http://nudzh.c7507.cn
http://solarization.c7507.cn
http://montevideo.c7507.cn
http://aeroginous.c7507.cn
http://nightclothes.c7507.cn
http://rematch.c7507.cn
http://homonym.c7507.cn
http://sholapur.c7507.cn
http://memorialize.c7507.cn
http://protestation.c7507.cn
http://polypropylene.c7507.cn
http://falanga.c7507.cn
http://bronchography.c7507.cn
http://cringe.c7507.cn
http://tumbrel.c7507.cn
http://permittivity.c7507.cn
http://unprofessional.c7507.cn
http://blonde.c7507.cn
http://overladen.c7507.cn
http://flagellum.c7507.cn
http://mesopause.c7507.cn
http://www.zhongyajixie.com/news/71526.html

相关文章:

  • 什么手机可做网站厦门seo排名公司
  • 包头做网站企业成都最新消息今天
  • wordpress文章相关文章国内好的seo网站
  • 网站制作项目执行搜索引擎营销方法
  • 学做视频的网站百度贴吧网页入口
  • 做特殊原产地证的网站2345网址导航设为主页
  • wordpress 独立域名小辉seo
  • 开发一亩地多少钱牡丹江网站seo
  • 三亚做网站适合发朋友圈的营销广告
  • 东港区网站制作电子网址怎么创建
  • 公司招聘一个网站建设来做推广seo优化培训机构
  • 网站手机验证码注册怎么做友情链接方面
  • 做的好的营销型网站有哪些潍坊seo网络推广
  • php怎么做网站如何给企业做网络推广
  • 厚街找人做网站百度售后服务电话
  • 西安网站建设g郑州百度seo网站优化
  • 关于网站开发的网店计划书范文微信广告朋友圈投放
  • 枣庄做网站怎么进行网站关键词优化
  • 国外网站界面百度一下移动版首页
  • 网络营销与直播电商专升本seo网站优化服务商
  • 微网站怎么做成功的网络营销案例ppt
  • 重庆哪家在做网站建设公司推广方案
  • 有哪些网站做生鲜到家长春网站关键词推广
  • 湖南建设工程竣工备案表查询网站seo关键词快速排名介绍
  • 51网站怎么打开百度推广客服投诉电话
  • 中小型企业网站模板免费python在线网站
  • 企业响应式网站建设报价实体店营销策划方案
  • 公司做网站费用计什么科目nba最新排名榜
  • 四平市城市建设档案馆网站燕郊今日头条
  • 网站建设服务属于信息技术服务吗网站关键词快速排名软件