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

做商贸网站推广类软文

做商贸网站,推广类软文,自己开公司 自己做网站吗,wordpress托管和建站Problem: 654. 最大二叉树 文章目录 题目描述思路复杂度Code 题目描述 思路 对于构造二叉树这类问题一般都是利用先、中、后序遍历,再将原始问题分解得出结果 1.定义递归函数build,每次将一个数组中的最大值作为当前子树的根节点构造二叉树;…

Problem: 654. 最大二叉树

文章目录

  • 题目描述
  • 思路
  • 复杂度
  • Code

题目描述

在这里插入图片描述在这里插入图片描述在这里插入图片描述在这里插入图片描述

思路

对于构造二叉树这类问题一般都是利用先、中、后序遍历,再将原始问题分解得出结果

1.定义递归函数build,每次将一个数组中的最大值作为当前子树的根节点构造二叉树;
2.每次找取当前范围内的最大值,作为当前的根节点;
3.递归求取出其左子树与右子树

复杂度

时间复杂度:

O ( n 2 ) O(n^2) O(n2);其中n为二叉树节点的个数

空间复杂度:

O ( n ) O(n) O(n)

Code

/*** Definition for a binary tree node.* public class TreeNode {*     int val;*     TreeNode left;*     TreeNode right;*     TreeNode() {}*     TreeNode(int val) { this.val = val; }*     TreeNode(int val, TreeNode left, TreeNode right) {*         this.val = val;*         this.left = left;*         this.right = right;*     }* }*/
class Solution {/*** Maximum Binary Tree** @param nums Given array* @return TreeNode*/public TreeNode constructMaximumBinaryTree(int[] nums) {return build(nums, 0, nums.length - 1);}/*** Construction of binary tree function implementation** @param nums Given array* @param low  Given the left endpoint of the array* @param high Given the right endpoint of the array* @return TreeNode*/TreeNode build(int[] nums, int low, int high) {if (low > high) {return null;}int index = -1;int maxVal = Integer.MIN_VALUE;for (int i = low; i <= high; ++i) {if (maxVal < nums[i]) {maxVal = nums[i];index = i;}}//The root node is constructed first,// and then the left and right subtrees are constructedTreeNode root = new TreeNode(maxVal);root.left = build(nums, low, index - 1);root.right = build(nums, index + 1, high);return root;}
}
http://www.zhongyajixie.com/news/46666.html

相关文章:

  • 安徽易企建站深圳龙华区大浪社区
  • 做设计的什么网站能挣钱培训网
  • 单纯的文章网站怎么做营销培训课程ppt
  • 美食类网站开发需求北京seo编辑
  • 地方门户网站建设方案沈阳seo优化新势力
  • 代练中介网站有得做吗买卖交易网
  • 做纺织外贸哪个贸易网站好关键词分为哪几类
  • 做网站 360最新新闻热点事件及评论
  • 域名禁止网站相关外贸建站教程
  • 数据交易网站开发百度竞价排名怎么靠前
  • 建网站需要什么资料百度收录时间
  • 网站布局的重要性什么是网络营销
  • 武汉做网站企业英文外链seo兼职在哪里找
  • 开发网站的流程细节百度博客收录提交入口
  • ios网站开发视频教程解封后中国死了多少人
  • 学做网站卖东西去哪学百度推广渠道户
  • wordpress 重写分页企业网站建设优化
  • 淄博市 网站建设报价全媒体广告代理加盟
  • 电子商城系统的设计与实现潜江seo
  • 建设网站需要花费什么费用深圳做网站的
  • wordpress文章发布广州seo公司品牌
  • 网站开发公司杭州百度怎么优化排名
  • 广州网站建设 .超凡科技现在有什么推广平台
  • 东莞模板建站哪家好seo培训资料
  • 摄影设计说明200字seo诊断专家
  • b2c电子商务网站制作百度指数数据来源
  • 网站搭建中转网站优化设计的基础是网站基本要素及每个细节的优化
  • app定制开发网站制作网络营销有哪些推广方式
  • wordpress 文章函数seo网站优化收藏
  • 这几年做哪些网站能致富设计网络推广方案