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

做网站运营用什么软件砀山做网站

做网站运营用什么软件,砀山做网站,wordpress数字商城模板下载,想建设个网站卖东西代码随想录day16| 找树左下角的值 、 路径总和 、 从中序与后序遍历序列构造二叉树 513找树左下角的值层序遍历法递归法 路径总和112. 路径总和113. 路径总和 II 从中序与后序遍历序列构造二叉树思路 513找树左下角的值 层序遍历法 使用层序遍历#xff0c;找到最后一层最左边… 代码随想录day16| 找树左下角的值 、 路径总和 、 从中序与后序遍历序列构造二叉树 513找树左下角的值层序遍历法递归法 路径总和112. 路径总和113. 路径总和 II 从中序与后序遍历序列构造二叉树思路 513找树左下角的值 层序遍历法 使用层序遍历找到最后一层最左边的数值每层循环的第一个值返回即可 class Solution {public int findBottomLeftValue(TreeNode root) {int res 0;QueueTreeNode queue new LinkedList();queue.offer(root);while(!queue.isEmpty()){int size queue.size();for(int i 0 ; i size ; i){TreeNode node queue.poll();if(i 0){res node.val;}if(node.left! null){queue.offer(node.left);}if(node.right ! null){queue.offer(node.right);}}} return res;}}递归法 使用递归遍历二叉树并且记录当前深度到根节点时更新最大深度的值然后使用回溯来更新其他路径时的深度 class Solution {int maxDeepth -1;int res 0;public int findBottomLeftValue(TreeNode root) {int deepth 0;getdeepthleft(root, deepth);return res;}public void getdeepthleft(TreeNode root, int deepth){if(root.left null root.right null){if(deepth maxDeepth){maxDeepth deepth;res root.val;return ;}return ;}if(root.left ! null){deepth 1;getdeepthleft(root.left, deepth);deepth - 1;}if(root.right ! null){deepth 1;getdeepthleft(root.right, deepth);deepth - 1;}} }路径总和 112. 路径总和 使用递归加回溯找出是否有符合目标的路径 class Solution {public boolean hasPathSum(TreeNode root, int targetSum) {if(root null){return false;}int sum 0;return getPath(root, sum, targetSum);}public boolean getPath(TreeNode root, int sum, int targetSum){if(root.left null root.right null){if(targetSum sum root.val){return true;}return false;}sum root.val;boolean left false;boolean right false;if(root.left ! null){left getPath(root.left, sum, targetSum);}if(root.right ! null){right getPath(root.right, sum, targetSum);}if(left || right){return true; }else{sum - root.val;return false;}} }113. 路径总和 II 这里相比上一个题目需要收集具体的符合目标的路径所以回溯两个值当前路径值的和sum 、当前收集的路径节点path class Solution {ListInteger path new ArrayList();ListListInteger paths new ArrayList();public ListListInteger pathSum(TreeNode root, int targetSum) {if(root null){return paths;}int sum 0;getPath(root, sum, targetSum);return paths;}public void getPath(TreeNode root, int sum, int targetSum){path.add(root.val);sum root.val;if(root.left null root.right null){if(targetSum sum){//这里注意新创建一个列表不能直接存原列表因为原列表后序会修改paths.add(new ArrayList(path));}return ;}if(root.left ! null){getPath(root.left, sum, targetSum);path.remove(path.size()-1);}if(root.right ! null){getPath(root.right, sum, targetSum);path.remove(path.size()-1);}}}从中序与后序遍历序列构造二叉树 思路 具体思路 注意切割数组时的边界处理 class Solution {public TreeNode buildTree(int[] inorder, int[] postorder) {return getTree(inorder, postorder);}public TreeNode getTree(int[] inorder, int[] postorder) {if(inorder null || postorder null){return null;}int val postorder[postorder.length-1];TreeNode root new TreeNode(val);if(inorder.length 1){return root;}int i 0;for(;i inorder.length ; i){if(inorder[i] val){break;}}int[] inorderLeft null;int[] inorderRight null;if(i 0){inorderLeft new int[i];for(int m 0 ; m i ; m){inorderLeft[m] inorder[m];}}if(i inorder.length-1){inorderRight new int[inorder.length-i-1];int n 0;for(int m i1 ; m inorder.length ; m){inorderRight[n] inorder[m];}}int j 0;int[] postorderLeft null;int[] postorderRight null;if(inorderLeft ! null){postorderLeft new int[inorderLeft.length];for(int m 0 ; m inorderLeft.length ; m){postorderLeft[m] postorder[m];}}if(inorderRight!null){postorderRight new int[inorderRight.length];int n 0;int m 0;if(inorderLeft ! null){m inorderLeft.length;}for(; m postorder.length-1 ; m){postorderRight[n] postorder[m];System.out.print(postorderRight[n] );n;}}root.left getTree(inorderLeft, postorderLeft);root.right getTree(inorderRight, postorderRight);return root;}}
http://www.w-s-a.com/news/570069/

相关文章:

  • 网站用户运营北京官方网站怎么做
  • 农业门户网站开发做首图的网站
  • wordpress 素材站模板怎么制作网站程序
  • 做ps合成的网站wordpress付费查看下载主题
  • 个人网站建设完整教程wordpress服务器搬迁
  • wordpress.主题广州 网站优化
  • 手机版网站怎样做推广如何用asp做视频网站
  • dede 网站打开慢七牛云 微信 打开 wordpress
  • 哪里网站建设公司比较好教育培训类网站模板
  • 中国建设银行官网首页网站wordpress小工具不能完全显示
  • 企业网站的开发流程是什么网站开发怎么销售
  • 现在网站还用asp做男科医院哪家好一些
  • 服装设计网站素材郑州汉狮做网站网络公司
  • 宜州做网站做仿制网站
  • 中山营销型网站厦门工程建设招聘信息网站
  • 网站开发 外包空心找回微信
  • 长沙市网站推广多少钱网站开发流程图和介绍
  • 网站后缀net施工企业自建自用的工程可以不进行招标是否正确
  • 鄂尔多斯市住房和城乡建设厅网站帮别人做网站赚钱6
  • 宜选科技就是帮人做网站动漫制作专业主修课程
  • 怎么做网站免费的教程温州捷创网站建设
  • 做免费推广的网站有哪些深圳华强北最新消息
  • 电子商务网站建设规划开题报告桂林漓江景区游玩攻略
  • 程序员参与洗钱网站建设做视频网站需要多少钱
  • 网站建设背景是什么企业邮箱怎么写
  • 山东省建设资格中心网站iis wordpress安装教程
  • 做的网站 显示乱码怎么做微信小程序平台
  • 怎样建设打字网站怎样增加网站浏览量
  • 网站建设方案的征求意见网站主机免备案
  • 共享农业网站建设郑州市建网站