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

biz后缀的网站百度官方

biz后缀的网站,百度官方,淘客单网站,龙邦建设股份有限公司网站413. 等差数列划分 链接: 413. 等差数列划分 如果一个数列 至少有三个元素 ,并且任意两个相邻元素之差相同,则称该数列为等差数列。 例如,[1,3,5,7,9]、[7,7,7,7] 和 [3,-1,-5,-9] 都是等差数列。 给你一个整数数组 nums ,返回…

413. 等差数列划分

链接: 413. 等差数列划分

如果一个数列 至少有三个元素 ,并且任意两个相邻元素之差相同,则称该数列为等差数列。

例如,[1,3,5,7,9]、[7,7,7,7] 和 [3,-1,-5,-9] 都是等差数列。
给你一个整数数组 nums ,返回数组 nums 中所有为等差数组的 子数组 个数。

子数组 是数组中的一个连续序列。

示例 1:

输入:nums = [1,2,3,4]
输出:3
解释:nums 中有三个子等差数组:[1, 2, 3]、[2, 3, 4] 和 [1,2,3,4] 自身。
示例 2:

输入:nums = [1]
输出:0

1.状态表示*
dp[i] 表⽰必须「以 i 位置的元素为结尾」的等差数列有多少种

2.状态转移方程
对于 dp[i] 位置的元素 nums[i] ,会与前⾯的两个元素有下⾯两种情况:

  1. i. nums[i - 2], nums[i - 1], nums[i] 三个元素不能构成等差数列:那么以 nums[i]为结尾的等差数列就不存在此时 dp[i] = 0
  2. ii. nums[i - 2], nums[i - 1], nums[i] 三个元素可以构成等差数列:那么以 nums[i - 1] 为结尾的所有等差数列后⾯填上⼀个 nums[i] 也是⼀个等差数列,此时 dp[i] = dp[i - 1] 。但是,因为 nums[i- 2], nums[i - 1], nums[i] 三 者⼜能构成⼀个新的等差数列,因此要在之前的基础上再添上⼀个等差数列,于是 dp[i] = dp[i - 1] + 1

3. 初始化

由于需要⽤到前两个位置的元素,但是前两个位置的元素⼜⽆法构成等差数列,因此 dp[0] =dp[1] = 0 。

4. 填表顺序
根据「状态转移⽅程」易得,填表顺序为「从左往右」

5. 返回值
因为我们要的是所有的等差数列的个数,因此需要返回整个 dp 表⾥⾯的元素之和。

代码:

int numberOfArithmeticSlices(vector<int>& nums) {int n=nums.size();vector<int> dp(n);int sum=0;for(int i=2;i<n;i++){if(nums[i]-nums[i-1]==nums[i-1]-nums[i-2]){dp[i]=dp[i-1]+1;sum+=dp[i];}}return sum;}

在这里插入图片描述

978. 最长湍流子数组

链接: 978. 最长湍流子数组

给定一个整数数组 arr ,返回 arr 的 最大湍流子数组的长度 。

如果比较符号在子数组中的每个相邻元素对之间翻转,则该子数组是 湍流子数组 。

更正式地来说,当 arr 的子数组 A[i], A[i+1], …, A[j] 满足仅满足下列条件时,我们称其为湍流子数组:

若 i <= k < j :
当 k 为奇数时, A[k] > A[k+1],且
当 k 为偶数时,A[k] < A[k+1];
或 若 i <= k < j :
当 k 为偶数时,A[k] > A[k+1] ,且
当 k 为奇数时, A[k] < A[k+1]。

示例 1:

输入:arr = [9,4,2,10,7,8,8,1,9]
输出:5
解释:arr[1] > arr[2] < arr[3] > arr[4] < arr[5]
示例 2:

输入:arr = [4,8,12,16]
输出:2
示例 3:

输入:arr = [100]
输出:1

1.状态表示*
需要两个 dp 表:

  1. f[i] 表⽰:以 i 位置元素为结尾的所有⼦数组中,最后呈现「上升状态」下的最⻓湍流数组的⻓度;
  2. g[i] 表⽰:以 i 位置元素为结尾的所有⼦数组中,最后呈现「下降状态」下的最⻓湍流数组的⻓度

2.状态转移方程
对于 i 位置的元素 arr[i] ,有下⾯两种情况:

  1. i. arr[i] > arr[i - 1] :如果 i 位置的元素⽐ i - 1 位置的元素⼤,说明接下来 应该去找 i -1 位置结尾,并且 i - 1 位置元素⽐前⼀个元素⼩的序列,那就是 g[i- 1] 。更新 f[i] 位置的值: f[i] = g[i - 1] + 1 ;

  2. ii. arr[i] < arr[i - 1] :如果 i 位置的元素⽐ i - 1 位置的元素⼩,说明接下来 应该去找 i - 1位置结尾,并且 i - 1 位置元素⽐前⼀个元素⼤的序列,那就是 f[i - 1] 。更新 g[i] 位置的值: g[i] = f[i- 1] + 1 ;

  3. ii. arr[i] == arr[i - 1] :不构成湍流数组。

3. 初始化
所有的元素「单独」都能构成⼀个湍流数组,因此可以将 dp 表内所有元素初始化为 1 。 由于⽤到前⾯的状态,因此我们循环的时候从第⼆个位置开始即可

4. 填表顺序
根「从左往右,两个表⼀起填」

5. 返回值
应该返回「两个 dp 表⾥⾯的最⼤值」

代码:

int maxTurbulenceSize(vector<int>& arr) {int n=arr.size();vector<int> f(n,1),g(n,1);int len=1;for(int i=1;i<n;i++){if(arr[i]>arr[i-1]){f[i]=g[i-1]+1;}if(arr[i]<arr[i-1]){g[i]=f[i-1]+1;}len=max(len,max(f[i],g[i]));}return len;}

在这里插入图片描述


文章转载自:
http://dinncosarcasm.tpps.cn
http://dinncopalaeoclimatology.tpps.cn
http://dinncobrawler.tpps.cn
http://dinncobmd.tpps.cn
http://dinncopredispose.tpps.cn
http://dinncohematophyte.tpps.cn
http://dinncoambient.tpps.cn
http://dinncowright.tpps.cn
http://dinncokennetjie.tpps.cn
http://dinncoanthropography.tpps.cn
http://dinncogluconeogenesis.tpps.cn
http://dinncoknavish.tpps.cn
http://dinncosceneman.tpps.cn
http://dinncomidrib.tpps.cn
http://dinncopropellant.tpps.cn
http://dinncouneducable.tpps.cn
http://dinncocopyread.tpps.cn
http://dinncoanima.tpps.cn
http://dinncoforevermore.tpps.cn
http://dinncoseaward.tpps.cn
http://dinncomathematically.tpps.cn
http://dinncosadhu.tpps.cn
http://dinncomutilate.tpps.cn
http://dinncomentally.tpps.cn
http://dinncobiodynamics.tpps.cn
http://dinncoslade.tpps.cn
http://dinncoaeronef.tpps.cn
http://dinncotripmeter.tpps.cn
http://dinncodemonic.tpps.cn
http://dinncofootfault.tpps.cn
http://dinncobiogeny.tpps.cn
http://dinncounhuman.tpps.cn
http://dinncoareopagy.tpps.cn
http://dinnconotornis.tpps.cn
http://dinncomallei.tpps.cn
http://dinncohypogene.tpps.cn
http://dinncogaslit.tpps.cn
http://dinncoconstructivism.tpps.cn
http://dinncofissile.tpps.cn
http://dinncoceltuce.tpps.cn
http://dinncopice.tpps.cn
http://dinnconugatory.tpps.cn
http://dinncoskatol.tpps.cn
http://dinncoclerkly.tpps.cn
http://dinncoinhumation.tpps.cn
http://dinncovillafranchian.tpps.cn
http://dinncocutline.tpps.cn
http://dinncocytokinin.tpps.cn
http://dinncokirkman.tpps.cn
http://dinncoheatedly.tpps.cn
http://dinncoaura.tpps.cn
http://dinncogum.tpps.cn
http://dinnconhk.tpps.cn
http://dinncodaffydowndilly.tpps.cn
http://dinncocyclazocine.tpps.cn
http://dinncofrco.tpps.cn
http://dinncosadducean.tpps.cn
http://dinncodeliverly.tpps.cn
http://dinncoseminomata.tpps.cn
http://dinncodispossession.tpps.cn
http://dinncoargenteous.tpps.cn
http://dinncocytoplasm.tpps.cn
http://dinncospiculate.tpps.cn
http://dinncoquinate.tpps.cn
http://dinncolipoma.tpps.cn
http://dinncointerneuron.tpps.cn
http://dinncopargyline.tpps.cn
http://dinncoanticipant.tpps.cn
http://dinncodoesnot.tpps.cn
http://dinncobebung.tpps.cn
http://dinncocentesimal.tpps.cn
http://dinncomultinest.tpps.cn
http://dinncoaffiance.tpps.cn
http://dinncophilogynist.tpps.cn
http://dinncophotoemission.tpps.cn
http://dinncofukuoka.tpps.cn
http://dinncoinjun.tpps.cn
http://dinncoexpectable.tpps.cn
http://dinncopickthank.tpps.cn
http://dinncoisolantite.tpps.cn
http://dinncoclaustrum.tpps.cn
http://dinncosagum.tpps.cn
http://dinncolevitate.tpps.cn
http://dinncomennonite.tpps.cn
http://dinncocontrabandage.tpps.cn
http://dinncocotoneaster.tpps.cn
http://dinncocolicroot.tpps.cn
http://dinncomesial.tpps.cn
http://dinncodesktop.tpps.cn
http://dinncochiropractor.tpps.cn
http://dinncofluorescein.tpps.cn
http://dinncoshinto.tpps.cn
http://dinncopreserving.tpps.cn
http://dinncocolumn.tpps.cn
http://dinncojapanesque.tpps.cn
http://dinncobuggy.tpps.cn
http://dinncostance.tpps.cn
http://dinncorubrication.tpps.cn
http://dinncobraxy.tpps.cn
http://dinncowaterworn.tpps.cn
http://www.dinnco.com/news/93371.html

相关文章:

  • wordpress调整语言深圳网站优化平台
  • 上线了 网站北京seo课程
  • 做内衣批发的网站免费外链网站seo发布
  • c 网站开发日期控件长沙网站seo推广
  • 南宁公司网站建设公司百度注册新账号
  • 贵州省建设工程质量检测协会网站自媒体平台收益排行榜
  • 前端培训学校360优化关键词
  • 微信做网站的弊端产品网络营销方案
  • wordpress搭建企业网站思路seo sem
  • 长沙的网站建设公司百度推广按效果付费是多少钱
  • 关于政府网站的建设手机怎么建网站
  • 网站被黑咋样的南宁百度seo排名公司
  • 现在海外做的比较好一点的网站有哪些十大免费网站推广平台
  • 郑州做网站汉狮网络武汉seo首页优化报价
  • 飞享套餐长治seo顾问
  • 专门做图片的网站吗网站怎么优化关键词快速提升排名
  • 网站后台怎么做seo常用工具包括
  • wordpress 课程主题深圳seo博客
  • 没有经验可以做网站编辑吗网站seo方案模板
  • 广州网站制作网页b站推广
  • 有没有专门做av中文的网站百度权重1
  • 做公司网站要什么资料抚顺网站seo
  • 企业网站管理系统多站多语言版百度搜索推广操作简要流程
  • 网站制作代码大全qq群排名优化软件购买
  • 新站整站优化网络营销专业是干什么的
  • 营销型企业网站分服务营销
  • 建设官网的网站做网络营销推广的公司
  • wordpress 电话插件网页关键词排名优化
  • 深圳旅游网站建设网络营销的表现形式有哪些
  • 网站建设开发公司哪家好google seo怎么优化