We define the conversion array conver
of an array arr
as follows:
conver[i] = arr[i] + max(arr[0..i])
where max(arr[0..i])
is the maximum value of arr[j]
over 0 <= j <= i
.
(相关资料图)
We also define the score of an array arr
as the sum of the values of the conversion array of arr
.
Given a 0-indexed integer array nums
of length n
, return an array ans
of length n
where ans[i]
is the score of the prefix nums[0..i]
.
Example 1:
Input: nums = [2,3,7,5,10]
Output: [4,10,24,36,56]
Explanation:
For the prefix [2], the conversion array is [4]
hence the score is 4
For the prefix [2, 3], the conversion array is [4, 6]
hence the score is 10
For the prefix [2, 3, 7], the conversion array is [4, 6, 14]
hence the score is 24
For the prefix [2, 3, 7, 5], the conversion array is [4, 6, 14, 12]
hence the score is 36
For the prefix [2, 3, 7, 5, 10], the conversion array is [4, 6, 14, 12, 20]
hence the score is 56
Example 2:
Input: nums = [1,1,2,4,8,16]
Output: [2,4,8,16,32,64]
Explanation:
For the prefix [1], the conversion array is [2]
hence the score is 2
For the prefix [1, 1], the conversion array is [2, 2]
hence the score is 4
For the prefix [1, 1, 2], the conversion array is [2, 2, 4]
hence the score is 8
For the prefix [1, 1, 2, 4], the conversion array is [2, 2, 4, 8]
hence the score is 16
For the prefix [1, 1, 2, 4, 8], the conversion array is [2, 2, 4, 8, 16]
hence the score is 32
For the prefix [1, 1, 2, 4, 8, 16], the conversion array is [2, 2, 4, 8, 16, 32]
hence the score is 64
先是计算convert数组,就是arr[i]+max((0-i)of arr[])
然后pre_sum;
最后返回即可,
不是难的题目;
可能提交的人少,所以数据看着还可以的。
Constraints:
1 <= nums.length <= 105
1 <= nums[i] <= 109
Accepted
12,032
Submissions
17,385
Runtime: 3 ms, faster than 100.00% of Java online submissions for Find the Score of All Prefixes of an Array.
Memory Usage: 72.5 MB, less than 100.00% of Java online submissions for Find the Score of All Prefixes of an Array.
关键词:
Wedefinetheconversionarrayconverofanarrayarrasfollows:conver[i]=arr[i]+max(arr[0 i])wheremax(arr[02023-04-16
点击查看2023-04-16
1、所有的步骤都写在图片上,看图片上的说明就行了。2、所有的步骤都写在图片上,看图片上的说明就行了。32023-04-16
国米0-1蒙扎北京时间4月16日,胜负彩第23051期结束全部14场比赛的争夺。本期胜负彩打出3场大冷,拜仁主场1-2023-04-16
1、拟秀丽绿绒蒿(学名:Meconopsispseudovenusta)是罂粟科绿绒蒿属植物,一年生草本,植株基部2023-04-16
1、蔡璋成为我国第一位专业的中文速记工作者。2、他将《传音快字》加以增删修改,于1921年正式出版了我国第2023-04-16
1、那个叫楼层卡,是服务员用的,必须要到总台的电脑上去设置权限。2、要不没有用的。本文到此分享完毕,希2023-04-15
央视网消息:今天(4月15日)是我国第八个全民国家安全教育日,各地开展了形式多样的宣传教育活动,提升全2023-04-15
新华社海口4月15日电通讯:“消博会为我们打开了一扇重要的大门”——古巴期待共享中国市场红利新华社记者2023-04-15
1、碧蓝航线也很适时的推出了七夕相关活动,并给十分受大家都非常喜欢的舰娘黑暗界推出了新皮肤“虚幻的幸2023-04-15
通俗的讲form标签是用来进行表单提交用的form标签里面的常见属性如下action:表单提交的地址,肯定是要提交2023-04-15
【永清集团、赣锋锂业等四方签约联合打造新能源产业链】4月14日,永清集团与新余市政府、大湾区基金、赣锋2023-04-15
上海男篮开售8进4G2球票:最贵680元最便宜180元,cba,上海队,上海男篮2023-04-15
我想给我80岁的女儿送个生日礼物,我想了半个月左右的生日,可是她8岁的生日我想送一些她没有新意和新意的2023-04-15
近日,“欧老师商业头脑”视频号发布了一则欧成效的视频发言内容,“没有几千万的话怎么能叫自己是人才呢?2023-04-15
一、题文海上生明月天涯共此时意思二、解答张九龄《望月怀远》海上生明月,天涯共此时 情人怨遥夜,竟夕起相2023-04-15
津滨海讯(记者牛婧文报道胡义和摄影)日前,科技部火炬中心企业创新积分制(北方片区)工作推进会在辽宁省2023-04-15
修身慎终如始,则无败事 点上方绿标收听主播诵读美文俗话说:“一着不慎,满盘皆输。”生活如大浪行舟,2023-04-15
全聚德迎来2023年开门红:一季度扭亏为盈,净利润超900万,全聚德,餐饮业,开门红,上市公司,公司股东2023-04-14
2023年4月13日-14日,由工业和信息化部、四川省人民政府共同主办的2023(第一届)全国产融合作大会举办。2023-04-14
编者按:4月13日至14日,聊城市召开文旅项目现场观摩会议,对全市8个县(市区)、3个市属开发区的22个文旅2023-04-14
①工信部指导腾讯公司做好重要业务系统安全稳定运行工作;②半导体板块大爆发,北方华创涨停!详情2023-04-14
人才是“第一资源”,培养数据安全人才是护航数字中国建设的重要任务,是推动数据安全产业健康发展的前提条2023-04-14
我们都以为,学习编程就是学写代码,但一名教授编程的老师指出:编程≠编码,更多时间都花在了工具问题上。2023-04-14
10碟充氦!希捷首款22TB机械硬盘发布:价格给力2023-04-14
