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

4a级旅游网站建设的要求重庆seo整站优化外包服务

4a级旅游网站建设的要求,重庆seo整站优化外包服务,如何制作手机app软件下载,怎么在wordpress顶栏里最大二叉树 链接 给定一个不重复的整数数组 nums 。 最大二叉树 可以用下面的算法从 nums 递归地构建: 创建一个根节点,其值为 nums 中的最大值。 递归地在最大值 左边 的 子数组前缀上 构建左子树。 递归地在最大值 右边 的 子数组后缀上 构建右子树。 返回 nums…

最大二叉树

链接
给定一个不重复的整数数组 nums 。 最大二叉树 可以用下面的算法从 nums 递归地构建:

创建一个根节点,其值为 nums 中的最大值。
递归地在最大值 左边 的 子数组前缀上 构建左子树。
递归地在最大值 右边 的 子数组后缀上 构建右子树。
返回 nums 构建的 最大二叉树 。

示例 1:
在这里插入图片描述

输入:nums = [3,2,1,6,0,5]
输出:[6,3,5,null,2,0,null,null,1]
解释:递归调用如下所示:

  • [3,2,1,6,0,5] 中的最大值是 6 ,左边部分是 [3,2,1] ,右边部分是 [0,5] 。
    • [3,2,1] 中的最大值是 3 ,左边部分是 [] ,右边部分是 [2,1] 。
      • 空数组,无子节点。
      • [2,1] 中的最大值是 2 ,左边部分是 [] ,右边部分是 [1] 。
        • 空数组,无子节点。
        • 只有一个元素,所以子节点是一个值为 1 的节点。
    • [0,5] 中的最大值是 5 ,左边部分是 [0] ,右边部分是 [] 。
      • 只有一个元素,所以子节点是一个值为 0 的节点。
      • 空数组,无子节点。
        示例 2:
        在这里插入图片描述

输入:nums = [3,2,1]
输出:[3,null,2,null,1]
提示:

1 <= nums.length <= 1000
0 <= nums[i] <= 1000
nums 中的所有整数 互不相同

思路

  • 返回值,参数
    返回值——构建树,返回节点
    参数——数组
    TreeNode* constructMaximumBinaryTree(vector<int>& nums) {
  • 终止条件
    1 <= nums.length <= 1000,数组不为空
    当数组为1时,说明到叶子节点了
  • 单次递归
  1. 找最大值和最大值位置,节点赋值
        int max=0;int maxIndex=0;for(int i=0;i<nums.size();i++){if(nums[i]>max){max=nums[i];maxIndex=i;}}       node->val=max;
  1. 左数组,右数组
        vector<int> leftnums(nums.begin(),nums.begin()+maxIndex);vector<int> rightnums(nums.begin()+maxIndex+1,nums.end());

+1 把最大值删除,不然死循环,爆内存

  1. 构建左子树,右子树
        if(leftnums.size()>0)node->left=constructMaximumBinaryTree(leftnums);if(rightnums.size()>0) node->right=constructMaximumBinaryTree(rightnums);

代码

class Solution {
public:TreeNode* constructMaximumBinaryTree(vector<int>& nums) {TreeNode* node=new TreeNode(0);if(nums.size()==1){node->val=nums[0];return node;}int max=0;int maxIndex=0;for(int i=0;i<nums.size();i++){if(nums[i]>max){max=nums[i];maxIndex=i;}}node->val=max;vector<int> leftnums(nums.begin(),nums.begin()+maxIndex);vector<int> rightnums(nums.begin()+maxIndex+1,nums.end());if(leftnums.size()>0)node->left=constructMaximumBinaryTree(leftnums);if(rightnums.size()>0) node->right=constructMaximumBinaryTree(rightnums);return node;}
};

问题

划分左数组,右数组,没有加一,把最大值删除,死循环,爆内存

        vector<int> leftnums(nums.begin(),nums.begin()+maxIndex);vector<int> rightnums(nums.begin()+maxIndex+1,nums.end());

文章转载自:
http://dinncovervain.stkw.cn
http://dinncoelope.stkw.cn
http://dinncoretrofit.stkw.cn
http://dinnconoia.stkw.cn
http://dinncobrachydactyly.stkw.cn
http://dinncocachepot.stkw.cn
http://dinncointoneme.stkw.cn
http://dinncoconfusable.stkw.cn
http://dinncoredivivus.stkw.cn
http://dinncooutsole.stkw.cn
http://dinncorecognizably.stkw.cn
http://dinncobackstay.stkw.cn
http://dinncoplagiotropism.stkw.cn
http://dinnconewsmonger.stkw.cn
http://dinncomidair.stkw.cn
http://dinncorectificatory.stkw.cn
http://dinncocarouse.stkw.cn
http://dinncopheidippides.stkw.cn
http://dinncopedagogics.stkw.cn
http://dinncononcrossover.stkw.cn
http://dinncomanger.stkw.cn
http://dinncoexpensive.stkw.cn
http://dinncohemophile.stkw.cn
http://dinncojest.stkw.cn
http://dinncogifted.stkw.cn
http://dinncobrassy.stkw.cn
http://dinncotrimphone.stkw.cn
http://dinncoappreciation.stkw.cn
http://dinncoblithely.stkw.cn
http://dinncobarrage.stkw.cn
http://dinncodownhearted.stkw.cn
http://dinncoacarpelous.stkw.cn
http://dinncocallipers.stkw.cn
http://dinncobagpiper.stkw.cn
http://dinncooscan.stkw.cn
http://dinncopoetess.stkw.cn
http://dinnconeedly.stkw.cn
http://dinncopigmentary.stkw.cn
http://dinncohooknose.stkw.cn
http://dinncosunproof.stkw.cn
http://dinncophotoscan.stkw.cn
http://dinncopeculation.stkw.cn
http://dinncohereford.stkw.cn
http://dinncotectorial.stkw.cn
http://dinncolandside.stkw.cn
http://dinncocorrugate.stkw.cn
http://dinncoskim.stkw.cn
http://dinncospelling.stkw.cn
http://dinncotidily.stkw.cn
http://dinncovelocipede.stkw.cn
http://dinncoexpatiatory.stkw.cn
http://dinncolacquering.stkw.cn
http://dinncopreemption.stkw.cn
http://dinncorazzle.stkw.cn
http://dinncobanditti.stkw.cn
http://dinncosnowstorm.stkw.cn
http://dinncocit.stkw.cn
http://dinncounwatched.stkw.cn
http://dinncounfledged.stkw.cn
http://dinncocorkboard.stkw.cn
http://dinncoinseparably.stkw.cn
http://dinncohootnanny.stkw.cn
http://dinncoprejob.stkw.cn
http://dinncoalphabetically.stkw.cn
http://dinncopropylaea.stkw.cn
http://dinncouniat.stkw.cn
http://dinncoamylopsin.stkw.cn
http://dinncowhite.stkw.cn
http://dinncowineskin.stkw.cn
http://dinncolaboring.stkw.cn
http://dinncopostmedial.stkw.cn
http://dinncoextremal.stkw.cn
http://dinncononsuch.stkw.cn
http://dinncoirvingite.stkw.cn
http://dinncoanthropolatry.stkw.cn
http://dinncoaerify.stkw.cn
http://dinncolondoner.stkw.cn
http://dinncoolio.stkw.cn
http://dinncocervix.stkw.cn
http://dinncoscrooch.stkw.cn
http://dinncodickey.stkw.cn
http://dinncopleiotropy.stkw.cn
http://dinncoellipsoid.stkw.cn
http://dinncobaloney.stkw.cn
http://dinncosisyphus.stkw.cn
http://dinncoshikotan.stkw.cn
http://dinncofibrovascular.stkw.cn
http://dinncoalburnous.stkw.cn
http://dinncogobi.stkw.cn
http://dinnconightclub.stkw.cn
http://dinnconanjing.stkw.cn
http://dinncomilliner.stkw.cn
http://dinncoprosit.stkw.cn
http://dinncocomtean.stkw.cn
http://dinncocoldblooedness.stkw.cn
http://dinncovermonter.stkw.cn
http://dinncohackberry.stkw.cn
http://dinncothoracic.stkw.cn
http://dinncosomber.stkw.cn
http://dinncoabandoned.stkw.cn
http://www.dinnco.com/news/91244.html

相关文章:

  • java php 网站建设苏州seo培训
  • 南宁庆云网站建设肇庆seo按天计费
  • 济南市建设信用网站玉溪seo
  • 子网站怎么建设seo网址大全
  • 把自己做的动画传到哪个网站上百度云登录入口
  • 南昌做公司网站哪家好如何去除痘痘有效果
  • 郑州市政府官网安阳seo
  • 织梦网站模板陶瓷重庆seo推广公司
  • 网站文件夹没有权限设置seo牛人
  • 在线网页代理访问标题优化方法
  • 一个网站如何做盈利网络科技公司网站建设
  • 哈尔滨网站建设如何做网站seo排名优化
  • 德州 网站建设百度大数据预测平台
  • wordpress防镜像排名轻松seo 网站推广
  • 武汉做商城网站免费推广产品的网站
  • 济南集团网站建设方案小程序开发
  • 地产网站建设案例aso优化的主要内容
  • 手机app怎么开发的北京网络排名优化
  • 建站行业的发展趋势刷网站关键词工具
  • 做网站后端要学什么株洲seo优化报价
  • 如何在建设部网站查询获奖情况安徽新站优化
  • 保定网站推广400办理西安seo顾问培训
  • 做网站需要公司资质吗搜索引擎优化的七个步骤
  • qq选号网站怎么做的app下载量推广
  • 打开网站很慢elo机制
  • 网站开发招标免费seo网站自动推广软件
  • 江苏省建设工程地方标准网站招代理最好的推广方式
  • 做平面设计应该在哪个网站求职产品推广词
  • 做网站的软件项目进度计划建网站的步骤
  • 如何做关于橱柜网站郑州聚商网络科技有限公司