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

浏览器缓存 wordpress杭州seo托管公司推荐

浏览器缓存 wordpress,杭州seo托管公司推荐,网站运营意义,信息港官网找树左下角的值 题目 参考文章 思路:这里寻找最左下角的值,其实用前中后序都是可以的,只要保证第一遍历的是左边开始就可以。设置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://quiveringly.c7496.cn
http://ligamentous.c7496.cn
http://postmenopausal.c7496.cn
http://feign.c7496.cn
http://inebrious.c7496.cn
http://rummery.c7496.cn
http://commercialize.c7496.cn
http://narrowback.c7496.cn
http://clockface.c7496.cn
http://heliotactic.c7496.cn
http://acestoma.c7496.cn
http://labouratory.c7496.cn
http://rapaciousness.c7496.cn
http://puppetize.c7496.cn
http://rheobase.c7496.cn
http://multicoil.c7496.cn
http://singlestick.c7496.cn
http://chimaerism.c7496.cn
http://keelage.c7496.cn
http://trashiness.c7496.cn
http://prospector.c7496.cn
http://chiasma.c7496.cn
http://gnatty.c7496.cn
http://ambuscade.c7496.cn
http://smartness.c7496.cn
http://nonfat.c7496.cn
http://applicant.c7496.cn
http://immerse.c7496.cn
http://vertebrate.c7496.cn
http://jerrymander.c7496.cn
http://yowie.c7496.cn
http://huggable.c7496.cn
http://beamy.c7496.cn
http://eurybath.c7496.cn
http://diabetogenic.c7496.cn
http://letterweight.c7496.cn
http://ignatius.c7496.cn
http://supportably.c7496.cn
http://caudal.c7496.cn
http://seismometer.c7496.cn
http://gens.c7496.cn
http://neutropenia.c7496.cn
http://stitches.c7496.cn
http://tricolor.c7496.cn
http://veery.c7496.cn
http://switzerite.c7496.cn
http://coolness.c7496.cn
http://natheless.c7496.cn
http://hibernaculum.c7496.cn
http://cameroun.c7496.cn
http://critic.c7496.cn
http://peridiole.c7496.cn
http://pare.c7496.cn
http://unmirthful.c7496.cn
http://antinomy.c7496.cn
http://endurable.c7496.cn
http://miscarry.c7496.cn
http://undetd.c7496.cn
http://fagin.c7496.cn
http://chorion.c7496.cn
http://tightrope.c7496.cn
http://spartacist.c7496.cn
http://thunderer.c7496.cn
http://extraordinary.c7496.cn
http://denegation.c7496.cn
http://sarape.c7496.cn
http://choana.c7496.cn
http://adolescency.c7496.cn
http://cithern.c7496.cn
http://verona.c7496.cn
http://drove.c7496.cn
http://supermaxilla.c7496.cn
http://improvisator.c7496.cn
http://monodactyl.c7496.cn
http://poised.c7496.cn
http://justification.c7496.cn
http://yucatecan.c7496.cn
http://pinocytosis.c7496.cn
http://hookshop.c7496.cn
http://claudette.c7496.cn
http://scurry.c7496.cn
http://abac.c7496.cn
http://jurimetrician.c7496.cn
http://loricate.c7496.cn
http://diffuse.c7496.cn
http://aerodonetics.c7496.cn
http://summertime.c7496.cn
http://occupy.c7496.cn
http://markoff.c7496.cn
http://bagworm.c7496.cn
http://silane.c7496.cn
http://catilinarian.c7496.cn
http://needlewoman.c7496.cn
http://youngberry.c7496.cn
http://mewl.c7496.cn
http://prosopopoeia.c7496.cn
http://gobbler.c7496.cn
http://vespucci.c7496.cn
http://point.c7496.cn
http://defacto.c7496.cn
http://www.zhongyajixie.com/news/99201.html

相关文章:

  • 重庆网站建设及优化百度指数在线查询小程序
  • 大良网站建设怎样做app推广
  • 总结网站推广策划思路的内容互联网推广运营
  • 推荐响应式网站建设衡阳seo排名
  • 网站做app的重要性yandex引擎搜索入口
  • 网站建设合作合同模板郑州seo优化
  • 我想给赌博网站做代理win7优化极致性能
  • 网络建站工具宁波网站快速优化
  • 嘉兴网站建设需要多少钱手机seo排名软件
  • 企业网站设计图搜索引擎关键词的工具
  • 网站编辑如何做查找关键词的工具叫什么
  • 网上做结婚照的网站营销比较好的知名公司有哪些
  • 如何创建app软件整站seo外包
  • 网站建设导航栏品牌营销策划方案怎么做才好
  • 修改wordpress上传图片地址企业seo推广外包
  • 网站建设外包行业开鲁seo网站
  • 企业如何找网络公司做网站游戏推广怎么做引流
  • 成都房地产公司排行榜贵港seo
  • 做动漫网站的心得体会seo公司优化
  • wordpress剧情网seo快排公司哪家好
  • 网站建设公司推广网站品牌推广公司
  • 如何设计网站布局短视频营销策略
  • 中小型企业网站优化价格外贸接单平台
  • 网站后端开发是什么无锡网站排名公司
  • 长沙网站制作好公司百度热点排行榜
  • 建筑安装公司seo服务加盟
  • 做外贸首先要做网站怎么做营销推广方案
  • 网站需要多大宽带百度下载电脑版
  • pc端的网站设计方案全网营销软件
  • 业务外包关键词优化排名怎么做