当前位置:网站首页>[daily 3 questions (2)] maximum ascending subarray sum
[daily 3 questions (2)] maximum ascending subarray sum
2022-06-28 16:58:00 【Programmed ape without hair loss 2】
subject :
I'll give you an array of positive integers nums , return nums In a Ascending The maximum possible elements of the subarray and .
A subarray is a sequence of consecutive numbers in an array .
Known subarray [numsl, numsl+1, …, numsr-1, numsr] , If for all i(l <= i < r),numsi < numsi+1 All set up , This subarray is called Ascending Subarray . Be careful , The size is 1 The subarray of is also treated as Ascending Subarray .
Example 1:
Input :nums = [10,20,30,5,10,50]
Output :65
explain :[5,10,50] Is the element and the largest ascending subarray , The largest sum of elements is 65 .
Example 2:
Input :nums = [10,20,30,40,50]
Output :150
explain :[10,20,30,40,50] Is the element and the largest ascending subarray , The largest sum of elements is 150 .
Example 3:
Input :nums = [12,17,15,13,10,11,12]
Output :33
explain :[10,11,12] Is the element and the largest ascending subarray , The largest sum of elements is 33 .
Example 4:
Input :nums = [100,10,1]
Output :100
Tips :
1 <= nums.length <= 100
1 <= nums[i] <= 100
Ideas :
One traverse , Record the cumulative sum of ascending order and the maximum value of accumulation , If found no longer ascending , Then recalculate the cumulative sum .
java Code :
class Solution {
public int maxAscendingSum(int[] nums) {
int sum = nums[0];
int max = nums[0];
for (int i = 1; i < nums.length; i++) {
if(nums[i]>nums[i-1]) {
sum+=nums[i];
}else {
sum = nums[i];
}
max = Math.max(max, sum);
}
return max;
}
}
边栏推荐
- 【TcaplusDB知识库】WebClient用户如何读取和修改数据
- Yesterday, yuancosmos | meta's "yuancosmos" Department lost $2.96 billion in the first quarter, and Liufu jewelry issued Digital Collections
- 编写自己的 WordPress 模板
- 小新黑苹果声卡ID注入
- NOIP1998-2018年普及组 CSP-J2 2019 2020 解题报告及视频
- PotPlayer播放百度云盘视频
- Must the database primary key be self incremented? What scenarios do not suggest self augmentation? ByteDance experience sharing using Flink state 𞓜 afternoon tea with sauce issue 16
- After the first failure, AMEC rushed to the Hong Kong stock exchange for the second time, and the financial principal changed frequently
- 使用 Open Connector 进行 HubSpot 和 SAP 系统的集成工作
- WPF 视频硬解码渲染播放(无空域)(支持4K、8K、高帧率视频)
猜你喜欢
QQ appears large-scale number theft, why is this? Is there no solution?
Csp-j1 csp-s1 preliminary training plan and learning points in summer and September 2022
使用Karmada实现Helm应用的跨集群部署
清华大佬耗时3天总结出的'常见网络协议汇总'
LTspice 电路仿真入门
This simple little function saves 213 hours for our production research team in half a year
Use open connector to integrate hubspot and SAP systems
CRM 全栈开发工具 WebClient UI Workbench 的设计细节介绍
关于接口测试自动化的总结与思考
中国SSD行业企业势力全景图
随机推荐
The intelligent transformation is accelerated, and enterprises need a new toolbox
【力扣】977. 有序数组的平方
On the design principle of price discount in SAP software
【尚硅谷与腾讯云官方合作】硅谷课堂项目视频发布
【TcaplusDB知识库】修改业务修改集群cluster
[redis] a brief summary of redis on January 31, 2021 No.01
这个简单的小功能,半年为我们产研团队省下213个小时
抓取手机端变体组合思路设想
【Golang】安装 iris 的方法
【世界海洋日】TcaplusDB号召你一同保护海洋生物多样性
CRM 全栈开发工具 WebClient UI Workbench 的设计细节介绍
天翼云Web应用防火墙(边缘云版)通过首批可信认证
np tips: random 创建随机矩阵 sample = np.random.random([19, 64 , 64, 3])
js中订阅发布模式bus
O & M - unified gateway is very necessary
强化 WordPress 的 11 种有效方法
你好,现在网上炒股开户买股票安全吗?
Coding Devops helps Sinochem information to build a new generation of research efficiency platform and drive the new future of "online Sinochem"
R 编程语言 - 简介
Langqing and Langchao, an ecological model from OEM to value symbiosis