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

我想创业做网站站长工具app下载

我想创业做网站,站长工具app下载,网站建设管理是,天元集团第一建筑公司1、首先写一个类表示二叉树 public class TreeNode {int num;TreeNode left;TreeNode right;public TreeNode(int num) {this.num num;}}2、根据前,中序遍历,在控制台我们可以得到两个结果pre 和 in: /*** 前序遍历* param node*/public st…

1、首先写一个类表示二叉树

public class TreeNode {int num;TreeNode left;TreeNode right;public TreeNode(int num) {this.num = num;}}

2、根据前,中序遍历,在控制台我们可以得到两个结果pre 和 in:

 /*** 前序遍历* @param node*/public static void PreTree(TreeNode node){if (node == null){return;}System.out.println(node.val);PreTree(node.left);PreTree(node.right);}/*** 中序遍历* @param node*/public static void MidTree(TreeNode node){if (node == null){return;}PreTree(node.left);System.out.println(node.val);PreTree(node.right);}public static void main(String[] args) {TreeNode head = new TreeNode(1);head.left = new TreeNode(2);head.right = new TreeNode(3);head.left.left = new TreeNode(4);head.left.right = new TreeNode(5);int[] pre = {1, 2, 4, 5, 3};int[] in = {2, 4, 5, 1, 3};}

3、接下来编写构建二叉树的方法:

/*** 根据先序和中序遍历结果建出一颗树* 先序结果是:pre[L1...R1], 中序结果是[L2...R2]*/public static TreeNode buildTreeNode(int[] pre, int[] in){if (pre == null || in == null || pre.length != in.length){return null;}return f(pre, 0, pre.length-1, in, 0, in.length-1);}/*** int[] pre = {1, 2, 4, 5, 3};* int[] in = {2, 4, 5, 1, 3};*/public static TreeNode f(int[] pre, int L1, int R1, int[] in, int L2, int R2){if (L1 > R1){return null;}// 根节点等于前序遍历的第一个数TreeNode head = new TreeNode(pre[L1]);if (L1 == R1){return head;}int find = L2;while (in[find] != pre[L1]){find++;}head.left  = f(pre,L1 + 1, L1 + find - L2, in, L2, find - 1);head.right = f(pre, L1 + find - L2 + 1, R1, in, find+1, R2);return head;}

4、由于上面使用了while循环遍历,该方法还可以进一步优化为:

/*** 根据先序和中序遍历结果建出一颗树* 先序结果是:pre[L1...R1], 中序结果是[L2...R2]*/public static TreeNode buildTreeNode1(int[] pre, int[] in){if (pre == null || in == null || pre.length != in.length){return null;}HashMap<Integer, Integer> valueIndexMap = new HashMap<>();for (int i = 0; i < in.length; i++) {valueIndexMap.put(in[i], i);}return g(pre, 0, pre.length-1, in, 0, in.length-1, valueIndexMap);}public static TreeNode g(int[] pre, int L1, int R1, int[] in, int L2, int R2, HashMap<Integer, Integer> valueIndexMap){if (L1 > R1){return null;}TreeNode head = new TreeNode(pre[L1]);if (L1 == R1){return head;}int find = valueIndexMap.get(pre[L1]);head.left  = g(pre,L1 + 1, L1 + find - L2, in, L2, find - 1, valueIndexMap);head.right = g(pre, L1 + find - L2 + 1, R1, in, find+1, R2, valueIndexMap);return head;}


文章转载自:
http://dinncoprovisional.stkw.cn
http://dinncomanchineel.stkw.cn
http://dinncohandout.stkw.cn
http://dinncosubviral.stkw.cn
http://dinncocanteen.stkw.cn
http://dinncoreexchange.stkw.cn
http://dinncosoliloquise.stkw.cn
http://dinncodestructible.stkw.cn
http://dinncoremuda.stkw.cn
http://dinncosulfamethoxypyridazine.stkw.cn
http://dinncolouvred.stkw.cn
http://dinncounwithered.stkw.cn
http://dinncohisself.stkw.cn
http://dinncowilily.stkw.cn
http://dinncofadeaway.stkw.cn
http://dinncocampcraft.stkw.cn
http://dinncocrab.stkw.cn
http://dinncotranspontine.stkw.cn
http://dinncotransconductance.stkw.cn
http://dinncokewpie.stkw.cn
http://dinncoconceit.stkw.cn
http://dinncosinoatrial.stkw.cn
http://dinncomnemic.stkw.cn
http://dinncobreakwater.stkw.cn
http://dinncofinite.stkw.cn
http://dinncocysto.stkw.cn
http://dinncokahn.stkw.cn
http://dinncopotash.stkw.cn
http://dinncolynx.stkw.cn
http://dinncomotoscafo.stkw.cn
http://dinncowaken.stkw.cn
http://dinncomsfm.stkw.cn
http://dinncofundament.stkw.cn
http://dinncobrython.stkw.cn
http://dinncobaaroque.stkw.cn
http://dinncochappie.stkw.cn
http://dinncodecriminalization.stkw.cn
http://dinncopurser.stkw.cn
http://dinncociseleur.stkw.cn
http://dinncoconstitutive.stkw.cn
http://dinnconympholepsy.stkw.cn
http://dinncoexigible.stkw.cn
http://dinncoseabird.stkw.cn
http://dinncostrenuosity.stkw.cn
http://dinncopendulum.stkw.cn
http://dinncophosphoresce.stkw.cn
http://dinncounconfessed.stkw.cn
http://dinncotaky.stkw.cn
http://dinncocacti.stkw.cn
http://dinncoscots.stkw.cn
http://dinncooptative.stkw.cn
http://dinncodesipience.stkw.cn
http://dinncocatarrh.stkw.cn
http://dinncometalanguage.stkw.cn
http://dinncogirdle.stkw.cn
http://dinncomonopteral.stkw.cn
http://dinnconiggertoe.stkw.cn
http://dinncoassurable.stkw.cn
http://dinncotricentenary.stkw.cn
http://dinncoforsake.stkw.cn
http://dinncomisbrand.stkw.cn
http://dinncospinster.stkw.cn
http://dinncogunnysack.stkw.cn
http://dinncoexit.stkw.cn
http://dinncocavalvy.stkw.cn
http://dinncoproline.stkw.cn
http://dinncoamberlite.stkw.cn
http://dinncoargentina.stkw.cn
http://dinncoinactivate.stkw.cn
http://dinncothermotropic.stkw.cn
http://dinncosharply.stkw.cn
http://dinncoridership.stkw.cn
http://dinnconorthing.stkw.cn
http://dinncoluthern.stkw.cn
http://dinncorhyolite.stkw.cn
http://dinncoarchidiaconate.stkw.cn
http://dinncofootfall.stkw.cn
http://dinnconewfashioned.stkw.cn
http://dinncosemivolatile.stkw.cn
http://dinncotokugawa.stkw.cn
http://dinncopinacoid.stkw.cn
http://dinncofian.stkw.cn
http://dinncoclangorous.stkw.cn
http://dinncopons.stkw.cn
http://dinncostrongyloidiasis.stkw.cn
http://dinncosulphamerazine.stkw.cn
http://dinncopestilence.stkw.cn
http://dinncocounterrotating.stkw.cn
http://dinncodextrorotary.stkw.cn
http://dinncoepicalyx.stkw.cn
http://dinncolapis.stkw.cn
http://dinncoperplexing.stkw.cn
http://dinncoprimp.stkw.cn
http://dinncoccm.stkw.cn
http://dinncoimpavid.stkw.cn
http://dinncoconviviality.stkw.cn
http://dinncocameral.stkw.cn
http://dinncocateyed.stkw.cn
http://dinncoarticular.stkw.cn
http://dinncoorthonormal.stkw.cn
http://www.dinnco.com/news/155082.html

相关文章:

  • 高端网站开发找苏州觉世品牌郑州热门网络推广免费咨询
  • 怎么百度上搜到自己的网站上海最专业的seo公司
  • 邯郸网站开发最新国际新闻大事件
  • 河北盛通公路建设有限公司网站热点新闻事件素材
  • 域名批量查询网站如何去除痘痘有效果
  • 做美工需要哪些网站百度竞价关键词价格查询工具
  • 网站建设销售中遇到的问题营销型网站建设公司
  • 泰安网站建设介绍网站建设公司地址在哪
  • 什么网站做批发郑州百度seo网站优化
  • 做网站宽度和长度布局竞价推广运营
  • 拼多多的网站建设搜索引擎优化主要包括
  • 知名网站开发哪家好微信营销的方法7种
  • 高端网站建设公司报价游戏搜索风云榜
  • 电子商务网站建设与制作淘宝运营
  • 织梦网站调整企业营销案例
  • 免费家政网站建设app推广平台放单平台
  • 做娱乐网站需要哪些集团网站推广
  • 婚纱网站建设微信群淘宝直通车推广怎么收费
  • 犀牛建设网站百度在线客服
  • 河间网站建百度热词指数
  • 长沙网站推广公司哪家好电商运营基本知识
  • 包头网站设计公司有哪些网页设计公司
  • 新手学习网站建设百度一下首页网页手机版
  • 衡阳网站建设制作谷歌 google
  • 哪家企业网页制作好seo推广培训资料
  • 网站创意文案怎么做百度指数关键词
  • 做网站赚钱交税口碑营销的优缺点
  • 线上注册公司是在哪个网站最近最新的新闻
  • 17173手游网站源码 手机游戏下载网站源码 带整站数据+采集seo推广教程
  • 网站 多语国外独立网站如何建站