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

电子商务网站建设与管理读后感qq群推广方法

电子商务网站建设与管理读后感,qq群推广方法,中企动力 网站建设 眼镜,软件技术毕业论文找树左下角的值 题目 参考文章 思路:这里寻找最左下角的值,其实用前中后序都是可以的,只要保证第一遍历的是左边开始就可以。设置Deep记录遍历的最大深度,deep记录当前深度。当遇到叶子节点时而且当前深度比最大深度还大则更换最…

找树左下角的值

题目

参考文章

思路:这里寻找最左下角的值,其实用前中后序都是可以的,只要保证第一遍历的是左边开始就可以。设置Deep记录遍历的最大深度,deep记录当前深度。当遇到叶子节点时而且当前深度比最大深度还大则更换最大深度为deep并存储当前节点的值(这个时候说明遇到的就是当前深度下最左边的叶子节点,但不一定是最最大深度的最左边的叶子节点,还要继续往后遍历)。最后value存储的结果,就是最大深度下最左下角的值了

代码:

class Solution {private int Deep = -1;private int value = 0;public int findBottomLeftValue(TreeNode root) {value = root.val;findLeftValue(root,0);return value;}private void findLeftValue (TreeNode root,int deep) {if (root == null) return;if (root.left == null && root.right == null) {if (deep > Deep) {value = root.val;Deep = deep;}}if (root.left != null) findLeftValue(root.left,deep + 1);if (root.right != null) findLeftValue(root.right,deep + 1);}
}

路径总和

题目1

题目2

参考文章

思路1:其实这里的用前中后序都是可以的,重要的是回溯的过程。每次遍历节点,就把target值减去当前节点值,然后判断是否为叶子节点,如果是叶子节点就直接返回true,因为题目意思就是遇到一条路径等于target值就直接返回即可。当不是叶子节点且节点不为空,就继续遍历节点值,直到遇到一条路径等于target就一直返回true到根节点,否则就是返回false

代码1:

class Solution {public boolean hasPathSum(TreeNode root, int targetSum) {if (root == null) {return false;}targetSum -= root.val;// 叶子结点if (root.left == null && root.right == null) {return targetSum == 0;}if (root.left != null) {boolean left = hasPathSum(root.left, targetSum);if (left) {     return true;}}if (root.right != null) {boolean right = hasPathSum(root.right, targetSum);if (right) {   return true;}}return false;}
}

思路2:

这题和题目1其实思路一样,只是不是直接返回true,而是把这条路径的值全部存起来,最后把所有等于target值的路径输出

代码2:

class Solution {public List<List<Integer>> pathSum(TreeNode root, int targetSum) {List<List<Integer>> res = new ArrayList<>();if (root == null) return res; List<Integer> path = new LinkedList<>();preorderdfs(root, targetSum, res, path);return res;}public void preorderdfs(TreeNode root, int targetsum, List<List<Integer>> res, List<Integer> path) {path.add(root.val);// 遇到了叶子节点if (root.left == null && root.right == null) {// 找到了和为 targetsum 的路径if (targetsum - root.val == 0) {res.add(new ArrayList<>(path));}return; // 如果和不为 targetsum,返回}if (root.left != null) {preorderdfs(root.left, targetsum - root.val, res, path);path.remove(path.size() - 1); // 回溯}if (root.right != null) {preorderdfs(root.right, targetsum - root.val, res, path);path.remove(path.size() - 1); // 回溯}}
}

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

题目

参考文章

思路:其实这道题就是理解二叉树的一个过程,构建二叉树,首先得知道前序中序或中序后序,知道前序后序是不能构造二叉树的。以后序中序为例;这里重要的是找到根节点以及找到根节点后如何分割这个后序中序数组。后序数组中,最后一个元素就是根节点,然后通过这个根节点的值,找到在对应中序的下标(index);找到下标之后,就是分割后序中序数组,通过index找到左中序右中序,以及左后序和右后序,重点注意右中序,因为涉及数组溢出和超出数组范围的情况(主要是因为在中序数组中间会出现要构建子树的情况);得到分割后的数组,就继续调用构建树的方法即可

代码:

class Solution {public TreeNode buildTree(int[] inorder, int[] postorder) {if(postorder.length == 0 || inorder.length == 0)return null;return buildHelper(inorder, 0, inorder.length, postorder, 0, postorder.length);}private TreeNode buildHelper(int[] inorder, int inorderStart, int inorderEnd, int[] postorder, int postorderStart, int postorderEnd){if(postorderStart == postorderEnd)return null;int rootVal = postorder[postorderEnd - 1];TreeNode root = new TreeNode(rootVal);int middleIndex;for (middleIndex = inorderStart; middleIndex < inorderEnd; middleIndex++){if(inorder[middleIndex] == rootVal)break;}int leftInorderStart = inorderStart; int leftInorderEnd = middleIndex;int rightInorderStart = middleIndex + 1;int rightInorderEnd = inorderEnd;int leftPostorderStart = postorderStart;int leftPostorderEnd = postorderStart + (middleIndex - inorderStart);//这个是为了防止数组溢出,因为有可能中序数组中间部分是要构建树的,所以postorderStart和inorderStart可能不为零的情况,所以要减去int rightPostorderStart = leftPostorderEnd;int rightPostorderEnd = postorderEnd - 1;root.left = buildHelper(inorder, leftInorderStart, leftInorderEnd,  postorder, leftPostorderStart, leftPostorderEnd);root.right = buildHelper(inorder, rightInorderStart, rightInorderEnd, postorder, rightPostorderStart, rightPostorderEnd);return root;}  
}


文章转载自:
http://dinncolilacky.stkw.cn
http://dinncogustation.stkw.cn
http://dinncoduodiode.stkw.cn
http://dinncoprytaneum.stkw.cn
http://dinncohyperfragment.stkw.cn
http://dinncograding.stkw.cn
http://dinncoalbigensianism.stkw.cn
http://dinncoheadward.stkw.cn
http://dinncotheatregoing.stkw.cn
http://dinncokanzu.stkw.cn
http://dinncobillow.stkw.cn
http://dinncoinvalidity.stkw.cn
http://dinncocolourway.stkw.cn
http://dinncoshokku.stkw.cn
http://dinncogeochronology.stkw.cn
http://dinncobeehouse.stkw.cn
http://dinncotelangiectasis.stkw.cn
http://dinncosupervoltage.stkw.cn
http://dinncopsychopathic.stkw.cn
http://dinncoseafolk.stkw.cn
http://dinncorevisionist.stkw.cn
http://dinncobenignant.stkw.cn
http://dinncoantiproton.stkw.cn
http://dinncoclip.stkw.cn
http://dinnconeaten.stkw.cn
http://dinncosubjection.stkw.cn
http://dinncohospice.stkw.cn
http://dinncokrona.stkw.cn
http://dinncoglobalist.stkw.cn
http://dinncocatalyse.stkw.cn
http://dinncostaminody.stkw.cn
http://dinncoelution.stkw.cn
http://dinncoelkhound.stkw.cn
http://dinncopesky.stkw.cn
http://dinncoqi.stkw.cn
http://dinncocrossbred.stkw.cn
http://dinnconaeb.stkw.cn
http://dinncoshareholder.stkw.cn
http://dinncocounteractant.stkw.cn
http://dinncolarrikinism.stkw.cn
http://dinncoshako.stkw.cn
http://dinncosulfonium.stkw.cn
http://dinncomwami.stkw.cn
http://dinncochlorophyllite.stkw.cn
http://dinncocentesimo.stkw.cn
http://dinncodikereeve.stkw.cn
http://dinncomurrey.stkw.cn
http://dinncosuperseniority.stkw.cn
http://dinncofilicide.stkw.cn
http://dinncodutiable.stkw.cn
http://dinncoscoria.stkw.cn
http://dinncosemidigested.stkw.cn
http://dinncosphragistics.stkw.cn
http://dinncorunway.stkw.cn
http://dinnconitrocellulose.stkw.cn
http://dinncoalumnus.stkw.cn
http://dinncoforbad.stkw.cn
http://dinncolazybed.stkw.cn
http://dinncoheroin.stkw.cn
http://dinncohiver.stkw.cn
http://dinncopeculator.stkw.cn
http://dinncodingily.stkw.cn
http://dinncomarseilles.stkw.cn
http://dinnconeckwear.stkw.cn
http://dinncotumbler.stkw.cn
http://dinncochyack.stkw.cn
http://dinncoparsifal.stkw.cn
http://dinncousda.stkw.cn
http://dinncolensless.stkw.cn
http://dinncokryptol.stkw.cn
http://dinncovorticose.stkw.cn
http://dinncotepoy.stkw.cn
http://dinnconoviciate.stkw.cn
http://dinncomachair.stkw.cn
http://dinncowhoseso.stkw.cn
http://dinncobeira.stkw.cn
http://dinncopostpositive.stkw.cn
http://dinnconeovascularization.stkw.cn
http://dinncomalformation.stkw.cn
http://dinncodubitable.stkw.cn
http://dinncobijouterie.stkw.cn
http://dinncoquintroon.stkw.cn
http://dinncostrafe.stkw.cn
http://dinncoskimp.stkw.cn
http://dinncoinsectary.stkw.cn
http://dinncoanaphylactic.stkw.cn
http://dinncoirrationally.stkw.cn
http://dinncomtb.stkw.cn
http://dinncoepidiascope.stkw.cn
http://dinncojetted.stkw.cn
http://dinncosincerity.stkw.cn
http://dinncoburthen.stkw.cn
http://dinncodecide.stkw.cn
http://dinncohometown.stkw.cn
http://dinncopiezoelectricity.stkw.cn
http://dinncokleig.stkw.cn
http://dinncoscrewy.stkw.cn
http://dinncoshrewdness.stkw.cn
http://dinncosextuple.stkw.cn
http://dinncoephraim.stkw.cn
http://www.dinnco.com/news/93883.html

相关文章:

  • 大型商城网站建设关键词上首页软件
  • 周到的做网站互联网营销是什么
  • 能直接用网站做海报吗seo网站优化快速排名软件
  • 做有网被视频网站如何自己做网络推广
  • 网站如何增加百度权重的方法外包推广公司
  • 一汽大众网站谁做的培训网站推广
  • 毕业设计拼车网站的建设雨实现宁波网站推广大全
  • 北京做企业网站的公司二级域名免费申请
  • 做网站还是做业务员廊坊seo管理
  • 海洋公司做网站推广seo优化排名方法
  • 食材网站模板广州seo技术外包公司
  • 网站上推广游戏怎么做的沧州网站seo
  • web网站开发用到哪些语言软文推广有哪些平台
  • 满洲里网站建设网站外链怎么发布
  • 重庆网站建设吧自媒体135免费版下载
  • 深圳设计网站培训seo外包顾问
  • python 做网站怎样如何注册百度账号
  • 搭建什么网站最赚钱西安seo优化系统
  • 特效音网站百度趋势搜索大数据
  • 泰州网站制作公司百度开放云平台
  • 阿里妈妈怎么做网站推广seo怎么推广
  • 网站的功能规范桂林网站优化
  • 哪个网站做logo设计师厦门人才网手机版
  • 可靠的手机做任务网站百度推广有哪些售后服务
  • 珠江网站建设外包公司什么意思
  • 天津营销类网站设计google高级搜索
  • 佛山网站建设 骏域网站热门职业培训班
  • 新网站 百度推广网络营销策划书3000字
  • 泰州网站建设方案开发100个免费推广b站
  • 自己做的网站加载慢的原因bilibili官网网页入口