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

河南卫生基层系统网站建设河南程序开发公司

河南卫生基层系统网站建设,河南程序开发公司,网站ip地址是什么,建设银行理财产品网站题目来源 力扣106从中序和后序遍历序列构造二叉树 题目概述 给定两个整数数组 inorder 和 postorder #xff0c;其中 inorder 是二叉树的中序遍历#xff0c; postorder 是同一棵树的后序遍历#xff0c;请你构造并返回这颗 二叉树 。 思路分析 后序遍历序列的最末尾数…题目来源 力扣106从中序和后序遍历序列构造二叉树 题目概述 给定两个整数数组 inorder 和 postorder 其中 inorder 是二叉树的中序遍历 postorder 是同一棵树的后序遍历请你构造并返回这颗 二叉树 。 思路分析 后序遍历序列的最末尾数据为树的根节点。 在中序遍历序列中找到树的根节点就可以找到这棵树的左子树范围和右子树范围。 分析方法与从前序与中序遍历序列构造二叉树类似。 代码实现 java实现 public class Solution {MapInteger, Integer inorderIndexMap new HashMap();public TreeNode buildTree(int[] inorder, int[] postorder) {// 中序遍历序列数据与下标映射便于后续查找for (int i 0; i inorder.length; i) {inorderIndexMap.put(inorder[i],i);}return create(inorder, postorder ,0, inorder.length - 1, 0, postorder.length - 1);}private TreeNode create(int[] inorder, int[] postorder, int iStart, int iEnd, int pStart, int pEnd) {if (pEnd pStart) {return null;}// 构建当前子树根节点int current postorder[pEnd];TreeNode root new TreeNode(current);// 当前节点在中序遍历序列的位置int rootIndexInInorder inorderIndexMap.get(current);// 右子树长度int rightSubTreeSize iEnd - rootIndexInInorder;// 构建左右子树root.right create(inorder,postorder, rootIndexInInorder 1, iEnd ,pEnd - rightSubTreeSize, pEnd - 1);root.left create(inorder,postorder, iStart,rootIndexInInorder - 1,pStart, pEnd - rightSubTreeSize - 1);return root;} }c实现 class Solution { public:unordered_mapint, int inorder_data_and_index;TreeNode* buildTree(vectorint inorder, vectorint postorder) {// 中序遍历序列数据与下标映射便于后续查找for (int i 0; i inorder.size(); i) {inorder_data_and_index[inorder[i]] i;}return create(inorder, postorder, 0, inorder.size() - 1, 0, postorder.size() - 1);}TreeNode* create(vectorint inorder, vectorint postorder, int iStart, int iEnd, int pStart, int pEnd) {if (pEnd pStart) {return nullptr;}// 构建当前子树根节点int current postorder[pEnd];TreeNode* root new TreeNode(current);// 当前节点在中序遍历序列的位置int rootIndexInInorder inorder_data_and_index[current];// 右子树长度int rightSubTreeSize iEnd - rootIndexInInorder;// 构建左右子树root-right create(inorder, postorder, rootIndexInInorder 1, iEnd, pEnd - rightSubTreeSize, pEnd - 1);root-left create(inorder, postorder, iStart, rootIndexInInorder - 1, pStart, pEnd - rightSubTreeSize - 1);return root;} }
http://www.w-s-a.com/news/441457/

相关文章:

  • 网站开发执行什么标准号wordpress主题 表白
  • 杭州网站推广与优化凡科网是免费的吗
  • 公司网站的重要性门户网站推广介绍方案
  • 做金融网站看那些素材江门网红打卡景点蓬江区
  • 饮食网站模板建网站中企动力优
  • 郑州 制造 网站东平企业建站公司
  • 天津设计师网站大全展示型网站搭建
  • 南宁网站建设 传导网站开发平台开发公司
  • 网站建设好处上海建设工程网站
  • 黑河哈尔滨网站建设太原网站制作定制开发
  • 建站做网站香河住房与建设局网站
  • 如何制造一个网站域名分类网站
  • 解析视频的网站怎么做凡科网快图
  • 企业网站优化问题接单app平台有哪些
  • 怎么做网站后缀识别符号才不会变什么是电子商务网站建设
  • 中山 五金 骏域网站建设专家专门用来制作网页的软件是什么
  • 怎么做刷东西的网站数据分析软件工具有哪些
  • 官方购物网站正品交易网站域名
  • lol网站建设seo 网站太小
  • 网站建设销售职责手机网站制作软件
  • 福州百度企业网站seo如何在电脑上登录wordpress
  • 开发区全力做好网站建设网络广告营销成功案例
  • 114网站建设高并发系统架构
  • php网站打开一片空白wordpress中文广告插件下载
  • 怎样建自己的网站免费的百度关键词排名点击
  • 医院网站建设的特点怎么查看网站百度快照
  • 网站 如何备案一般网站开发公司
  • 做网站的公司 贵阳郑州新像素ui设计培训收费
  • 温州网站建设公司电话给个免费的网址
  • 个人做电子商务网站备案软考高级