2321. 拼接数组的最大分数

题目链接 2321. 拼接数组的最大分数
思路 最大子数组和-变体
题解链接 转换成最大子数组和(Python/Java/C++/Go)
关键点
时间复杂度 O(n)
空间复杂度 O(1)

代码实现:

class Solution:
def maximumsSplicedArray(self, nums1: List[int], nums2: List[int]) -> int:
return max(
self.simpleSolution(nums1, nums2),
self.simpleSolution(nums2, nums1)
)
def simpleSolution(self, nums1, nums2):
maxv = presum = 0
for x, y in zip(nums1, nums2):
presum += y - x
if presum < 0: presum = 0
if presum > maxv: maxv = presum
return sum(nums1) + maxv
posted @   WrRan  阅读(5)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 单线程的Redis速度为什么快?
· 展开说说关于C#中ORM框架的用法!
· Pantheons:用 TypeScript 打造主流大模型对话的一站式集成库
· SQL Server 2025 AI相关能力初探
· 为什么 退出登录 或 修改密码 无法使 token 失效
点击右上角即可分享
微信分享提示