当前位置:网站首页>[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;
}
}
边栏推荐
- 2019 CSP J2入门组 CSP-S2提高组 第2轮 视频与题解
- After the first failure, AMEC rushed to the Hong Kong stock exchange for the second time, and the financial principal changed frequently
- 清华大佬耗时3天总结出的'常见网络协议汇总'
- C#/VB.NET 将PDF转为Excel
- 【208】基于AccessToken方式实现API设计
- 老司机总结的12条 SQL 优化方案(非常实用)
- offsetwidth\clientwidth\scrollwidth
- 基于DataWorks的时效仿真平台|得物技术
- Introduction to LTSpice circuit simulation
- Practice of curve replacing CEPH in Netease cloud music
猜你喜欢

MATLB|电力系统优化运行与市场化

CRM 全栈开发工具 WebClient UI Workbench 的设计细节介绍

免费、强大、高颜值的笔记软件评测: OneNote、Heptabase、氢图、FlowUs

抓取手机端变体组合思路设想

基数排序——【常见排序法(2/8)】

QQ appears large-scale number theft, why is this? Is there no solution?
![[golang] how to install iris](/img/c6/842c4e920a74f9a07c2f6a82bb0cc1.png)
[golang] how to install iris

中国SSD行业企业势力全景图
Super detailed steps for MySQL master-slave switching

After the first failure, AMEC rushed to the Hong Kong stock exchange for the second time, and the financial principal changed frequently
随机推荐
NOIP2011-2018提高组解题报告
Subscription publishing mode bus in JS
【每日3题(2)】最大升序子数组和
知乎热问:一个程序员的水平能差到什么程度?
强化 WordPress 的 11 种有效方法
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
Hello, is it safe to open an account to buy stocks online?
如何登录到你的 WordPress 管理仪表板
You have a chance to collect wool. Click "earn" and you will have a chance to earn a high commission
Super detailed steps for MySQL master-slave switching
[tcapulusdb knowledge base] view the business password
【TcaplusDB知识库】WebClient用户如何读取和修改数据
PostgreSQL exception handling
天翼云Web应用防火墙(边缘云版)通过首批可信认证
Interview with wangyuntao of China Academy of information technology: digital and real integration enables the prosperity and development of cultural industry
Can SQL queries be used in the tablestore to find out all the data in the table?
GCC efficient graph revolution for joint node representationlearning and clustering
抓取手机端变体组合思路设想
Stm32cubemx usage and function introduction
PotPlayer播放百度雲盤視頻