最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

LeetCode 2640. Find the Score of All Prefixes of an Array

2023-04-16 12:57 作者:您是打尖兒還是住店呢  | 我要投稿

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數(shù)組,就是arr[i]+max((0-i)of arr[])

然后pre_sum;

最后返回即可,

不是難的題目;

可能提交的人少,所以數(shù)據(jù)看著還可以的。

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.


LeetCode 2640. Find the Score of All Prefixes of an Array的評論 (共 條)

分享到微博請遵守國家法律
理塘县| 黎城县| 邵东县| 达州市| 滨海县| 石河子市| 嘉善县| 安塞县| 唐海县| 平遥县| 乌兰县| 平山县| 赫章县| 民县| 娱乐| 铁力市| 八宿县| 高唐县| 屯门区| 天津市| 余干县| 辰溪县| 田阳县| 秦皇岛市| 临城县| 开原市| 巴彦县| 拉萨市| 江华| 荆州市| 石阡县| 肇源县| 镇远县| 新郑市| 子长县| 麦盖提县| 大名县| 大冶市| 长乐市| 正安县| 徐水县|