加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

[Swift]LeetCode1191.

发布时间:2020-12-14 04:26:13 所属栏目:百科 来源:网络整理
导读:★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★ ?微信公众号:为敢(WeiGanTechnologies) ?博客园地址:山青咏芝(https://www.cnblogs.com/strengthen/) ?GitHub地址:https://github.com/strengthen/LeetCode ?原文

★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★
?微信公众号:为敢(WeiGanTechnologies)
?博客园地址:山青咏芝(https://www.cnblogs.com/strengthen/)
?GitHub地址:https://github.com/strengthen/LeetCode
?原文地址:https://www.cnblogs.com/strengthen/p/11521662.html
?如果链接不是山青咏芝的博客园地址,则可能是爬取作者的文章。
?原文已修改更新!强烈建议点击原文地址阅读!支持作者!支持原创!
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★

Given an integer array?arr?and an integer?k,modify the array by repeating it?k?times.

For example,if?arr?= [1,2]?and?k = 3?then the modified array will be?[1,2,1,2].

Return the maximum sub-array sum in the modified array. Note that the length of the sub-array can be?0?and its sum in that case is?0.

As the answer can be very large,return the answer?modulo?10^9 + 7.

?

Example 1:

Input: arr = [1,2],k = 3
Output: 9

Example 2:

Input: arr = [1,-2,1],k = 5
Output: 2

Example 3:

Input: arr = [-1,-2],k = 7
Output: 0

?

Constraints:

  • 1 <= arr.length <= 10^5
  • 1 <= k <= 10^5
  • -10^4 <= arr[i] <= 10^4

给你一个整数数组?arr?和一个整数?k

首先,我们要对该数组进行修改,即把原数组?arr?重复?k?次。

举个例子,如果?arr?= [1,2]?且?k = 3,那么修改后的数组就是?[1,2]

然后,请你返回修改后的数组中的最大的子数组之和。

注意,子数组长度可以是?0,在这种情况下它的总和也是?0

由于?结果可能会很大,所以需要?模(mod)?10^9 + 7?后再返回。?

?

示例 1:

输入:arr = [1,k = 3
输出:9

示例 2:

输入:arr = [1,k = 5
输出:2

示例 3:

输入:arr = [-1,k = 7
输出:0

?

提示:

  • 1 <= arr.length <= 10^5
  • 1 <= k <= 10^5
  • -10^4 <= arr[i] <= 10^4

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读