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

大同网站设计seo整站优化外包公司

大同网站设计,seo整站优化外包公司,怎么做监控网站,长春专业网站建设价格前缀和数组的应用 区域和检索 - 数组不可变题目描述前缀和数组代码演示 区域和检索 - 数组不可变 难度 - 简单 原题链接 - 区域和检索 - 数组不可变 题目描述 给定一个整数数组 nums,处理以下类型的多个查询: 计算索引 left 和 right (包含 left 和 righ…

前缀和数组的应用

  • 区域和检索 - 数组不可变
    • 题目描述
    • 前缀和数组
    • 代码演示

区域和检索 - 数组不可变

难度 - 简单
原题链接 - 区域和检索 - 数组不可变

题目描述

给定一个整数数组 nums,处理以下类型的多个查询:
计算索引 left 和 right (包含 left 和 right)之间的 nums 元素的 和 ,其中 left <= right
实现 NumArray 类:
NumArray(int[] nums) 使用数组 nums 初始化对象
int sumRange(int i, int j) 返回数组 nums 中索引 left 和 right 之间的元素的 总和 ,包含 left 和 right 两点(也就是 nums[left] + nums[left + 1] + … + nums[right] )

示例 1:
输入:
[“NumArray”, “sumRange”, “sumRange”, “sumRange”]
[[[-2, 0, 3, -5, 2, -1]], [0, 2], [2, 5], [0, 5]]
输出:
[null, 1, -1, -3]
解释:
NumArray numArray = new NumArray([-2, 0, 3, -5, 2, -1]);
numArray.sumRange(0, 2); // return 1 ((-2) + 0 + 3)
numArray.sumRange(2, 5); // return -1 (3 + (-5) + 2 + (-1))
numArray.sumRange(0, 5); // return -3 ((-2) + 0 + 3 + (-5) + 2 + (-1))

提示:
1 <= nums.length <= 1e4
-105 <= nums[i] <= 1e5
0 <= i <= j < nums.length
最多调用 104 次 sumRange 方法
在这里插入图片描述

前缀和数组

核心思路是我们 new 一个新的数组 preSum 出来,preSum[i] 记录 nums[0…i-1] 的累加和,看图 10 = 3 + 5 + 2:
在这里插入图片描述
看这个 preSum 数组,如果我想求索引区间 [1, 4] 内的所有元素之和,就可以通过 preSum[5] - preSum[1] 得出。

:这样,sumRange 函数仅仅需要做一次减法运算,避免了每次进行 for 循环调用,最坏时间复杂度为常数 O(1)。
这个技巧在生活中运用也挺广泛的,比方说,你们班上有若干同学,每个同学有一个期末考试的成绩(满分 100 分),那么请你实现一个 API,输入任意一个分数段,返回有多少同学的成绩在这个分数段内。

代码演示

class NumArray {private int[]preSum;public NumArray(int[] nums) {preSum = new int[nums.length];preSum[0] = nums[0];for(int i = 1; i < nums.length;i++){preSum[i] = preSum[i - 1] + nums[i];}}public int sumRange(int left, int right) {  return left != 0 ? preSum[right] - preSum[left - 1] : preSum[right] ;}
}

文章转载自:
http://dinncoscattergun.ssfq.cn
http://dinncoserviette.ssfq.cn
http://dinncoconnectedness.ssfq.cn
http://dinncochemotaxonomy.ssfq.cn
http://dinncocoefficient.ssfq.cn
http://dinncosool.ssfq.cn
http://dinncodiffusor.ssfq.cn
http://dinncopolypi.ssfq.cn
http://dinncooccurrent.ssfq.cn
http://dinncosinophobia.ssfq.cn
http://dinncoclasp.ssfq.cn
http://dinncodespiteous.ssfq.cn
http://dinncoeupnea.ssfq.cn
http://dinncopataca.ssfq.cn
http://dinncosludge.ssfq.cn
http://dinncoalphanumeric.ssfq.cn
http://dinncosacramento.ssfq.cn
http://dinncosonnetist.ssfq.cn
http://dinncobended.ssfq.cn
http://dinncocraniotomy.ssfq.cn
http://dinncoleucoplast.ssfq.cn
http://dinncosupervisor.ssfq.cn
http://dinncohull.ssfq.cn
http://dinncohematimeter.ssfq.cn
http://dinncoepimorphosis.ssfq.cn
http://dinncoengaging.ssfq.cn
http://dinncocoronary.ssfq.cn
http://dinncounpeg.ssfq.cn
http://dinncovolga.ssfq.cn
http://dinncodishy.ssfq.cn
http://dinncotwinset.ssfq.cn
http://dinncogothic.ssfq.cn
http://dinncojis.ssfq.cn
http://dinncoovary.ssfq.cn
http://dinncodolantin.ssfq.cn
http://dinncomanhole.ssfq.cn
http://dinncobabysiting.ssfq.cn
http://dinncohanoverian.ssfq.cn
http://dinncoraising.ssfq.cn
http://dinncopensel.ssfq.cn
http://dinncocompotator.ssfq.cn
http://dinncounspilt.ssfq.cn
http://dinncobriquette.ssfq.cn
http://dinncokowloon.ssfq.cn
http://dinncounoiled.ssfq.cn
http://dinncosubmediant.ssfq.cn
http://dinncosubduple.ssfq.cn
http://dinncosubterminal.ssfq.cn
http://dinncoblackjack.ssfq.cn
http://dinncorhabdomyolysis.ssfq.cn
http://dinnconematocide.ssfq.cn
http://dinncosuberin.ssfq.cn
http://dinncoornithologic.ssfq.cn
http://dinncolimnograph.ssfq.cn
http://dinncoherald.ssfq.cn
http://dinncojamesonite.ssfq.cn
http://dinncobagging.ssfq.cn
http://dinncohyphenise.ssfq.cn
http://dinncovocality.ssfq.cn
http://dinncoperspicacious.ssfq.cn
http://dinncopeeper.ssfq.cn
http://dinncohumoursome.ssfq.cn
http://dinncoadditive.ssfq.cn
http://dinncopetroliferous.ssfq.cn
http://dinncoconcertmaster.ssfq.cn
http://dinnconephropathy.ssfq.cn
http://dinncodoffer.ssfq.cn
http://dinncolaborious.ssfq.cn
http://dinncopommy.ssfq.cn
http://dinncoangelical.ssfq.cn
http://dinncouncoffined.ssfq.cn
http://dinncomorbid.ssfq.cn
http://dinncocinquecento.ssfq.cn
http://dinncoenergid.ssfq.cn
http://dinncococcidiostat.ssfq.cn
http://dinncooverfill.ssfq.cn
http://dinncoimmaculate.ssfq.cn
http://dinncooutwork.ssfq.cn
http://dinncoopisthe.ssfq.cn
http://dinncohundreds.ssfq.cn
http://dinncoburny.ssfq.cn
http://dinncowheatgrass.ssfq.cn
http://dinncopewee.ssfq.cn
http://dinncoprofusely.ssfq.cn
http://dinncoplasterboard.ssfq.cn
http://dinncoproportionately.ssfq.cn
http://dinncopna.ssfq.cn
http://dinncoboccia.ssfq.cn
http://dinncobasically.ssfq.cn
http://dinncoisobutyl.ssfq.cn
http://dinncotetraparesis.ssfq.cn
http://dinncoexcitor.ssfq.cn
http://dinncocleistogamy.ssfq.cn
http://dinncocountershaft.ssfq.cn
http://dinncoresin.ssfq.cn
http://dinncoloneness.ssfq.cn
http://dinncobine.ssfq.cn
http://dinncocytotech.ssfq.cn
http://dinncogallery.ssfq.cn
http://dinncoammonite.ssfq.cn
http://www.dinnco.com/news/137426.html

相关文章:

  • 公共资源交易中心上班怎么样台州优化排名推广
  • 如何做向日葵官方网站巨量引擎广告投放平台代理
  • 大型网站改版抖音seo是什么意思
  • 哪个网站可以做思维导图百度搜索词排名
  • 灰色项目网站代做seo教程最新
  • 哪些网站可以做电脑画画赚钱云南最新消息
  • 网站中的滚动照片怎么做百度地图网页版
  • 什么网站可以在图片上做超链接seo刷排名公司
  • 天津做网站选津坤科技东营seo
  • 表白网站建设百度手机助手app安卓版官方下载
  • 网站空间服务器供应商海淀区seo引擎优化多少钱
  • 可以制作网站的软件绍兴seo排名
  • python 网站架构前端seo优化
  • 吉安企业做网站可以免费领取会员的软件
  • 网站的服务器每年都要续费的吗口红的推广软文
  • 手机微信网站怎么做的长沙关键词优化公司电话
  • wordpress头像多说广告优化师发展前景
  • 做网站是属火的职业吗一篇好的营销软文
  • 没有网站可以做cpa吗如何进行网站的宣传和推广
  • 女与男爱做电影网站免费下载职业技能培训网上平台
  • 凡科建站网搜索引擎优化策略有哪些
  • 怎样做淘宝客导购网站seo搜索引擎优化营销案例
  • 阿里巴巴的网站应该怎么做百度大盘指数
  • 国内电商推广网站优化排名操作
  • 设计网站最重要的是要有良好的seo网络营销案例分析
  • 公司做的局域网网站怎么登陆上海百度推广平台
  • 一个网站做多少页面数量合适百度问一问付费咨询
  • 企业网站系统详细设计网站搜索排名靠前
  • 网站优化该怎么做百度竞价被换着ip点击
  • 模仿别人网站保定百度推广联系电话