当前位置:网站首页>leetcode:918. Maximum sum of circular subarray [reverse thinking + maximum subarray sum]
leetcode:918. Maximum sum of circular subarray [reverse thinking + maximum subarray sum]
2022-06-25 13:20:00 【Review of the white speed Dragon King】

analysis
This question If it is not a ring, the normal subarray is OK If you find out maxn Less than 0, All negative numbers , Just go back
otherwise Start thinking about having rings , It's one end at a time , Then you need the least in the middle , So it's the minimal array and
And then use sum Just subtract it
ac code
class Solution:
def maxSubarraySumCircular(self, nums: List[int]) -> int:
# acyclic : Normal maximum subarray and
maxn = -inf
now = 0
for num in nums:
now += num
maxn = max(maxn, now)
now = max(0, now)
if maxn < 0:
return maxn # All negative numbers
# Ring : Normal minimal arrays and
minn = inf
now = 0
for num in nums:
now += num
minn = min(minn, now)
now = min(0, now)
# The maximum value in a ring without a ring
return max(maxn, sum(nums) - minn)
summary
Thinking questions
边栏推荐
- Used in time filter (EL table)
- 解析數倉lazyagg查詢重寫優化
- Reload cuda/cudnn/pytorch
- 15 basic SEO skills to improve ranking
- 初始c语言的知识2.0
- [turn] starting from the end, analyze in detail how to fill in the college entrance examination volunteer
- WIN10环境下配置pytorch
- MySQL 学习笔记
- Maui's learning path (II) -- setting
- 关于结构体,枚举,联合的一些知识
猜你喜欢

Analyse de l'optimisation de la réécriture des requêtes lazyagg de l'entrepôt

Confusion caused by the ramp

Resolution of PPT paper drawing
![[AI helps scientific research] fool drawing of loss curve](/img/38/5cb2a3d33a609dab3874215d5f7b5b.png)
[AI helps scientific research] fool drawing of loss curve

mysql导入导出数据到excel表日期出现问题

Detailed explanation of string operation functions and memory functions

Shenzhen mintai'an intelligent second side_ The first offer of autumn recruitment

golang键盘输入语句scanln scanf代码示例
![[data visualization] antv L7 realizes map visualization, drilldownlayer drill asynchronously obtains data, and suspends the warning box](/img/81/f8280f16efa314d736c3a869c32ef0.jpg)
[data visualization] antv L7 realizes map visualization, drilldownlayer drill asynchronously obtains data, and suspends the warning box

An article clearly explains MySQL's clustering / Federation / coverage index, back to table, and index push down
随机推荐
三行代码简单修改jar包的项目代码
Resolution of PPT paper drawing
ByteDance dev better technology salon is coming! Participate in the activity to win a good gift, and sign up for free within a limited time!
Download File blob transcoding
.NET in China - What's New in .NET
[data visualization] antv L7 realizes map visualization, drilldownlayer drill asynchronously obtains data, and suspends the warning box
解析數倉lazyagg查詢重寫優化
[machine learning] what is machine learning?
Sword finger offer 04 Find in 2D array
字节跳动Dev Better技术沙龙来啦!参与活动赢好礼,限时免费报名中!
Storage related contents of data in memory
学习编程的起点。
[turn] starting from the end, analyze in detail how to fill in the college entrance examination volunteer
剑指 Offer 第 1 天栈与队列(简单)
À propos du stockage des données en mémoire
J2EE from entry to earth 01 MySQL installation
始终保持疫情防控不放松 营造安全稳定的社会环境
An article clearly explains MySQL's clustering / Federation / coverage index, back to table, and index push down
Back test of quantitative trading - tqzfuturerenkowavestrategy
Confusion caused by the ramp