当前位置:网站首页>Yyds dry goods inventory # solve the real problem of famous enterprises: continuous maximum sum
Yyds dry goods inventory # solve the real problem of famous enterprises: continuous maximum sum
2022-07-04 14:36:00 【51CTO】
1. sketch :
describe
An array has N Elements , Find the maximum sum of successive subarrays . for example :[-1,2,1], And the largest continuous subarray is [2,1], The sum is 3
Input description :
Enter in two lines . The first line is an integer n(1 <= n <= 100000), Means that there are n Elements Second behavior n Number , That is, every element , Every integer is in 32 position int Within the scope of . Space off .
Output description :
The largest value in all successive subarrays .
Example 1
Input :
Output :
2. Code implementation :
import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int sums=0, maxsums=Integer.MIN_VALUE; // Consider the case of all negative numbers
for(int i=0;i<n;i++){
sums+=sc.nextInt();
maxsums=Math.max(maxsums,sums);
sums= sums<0?0:sums; // Code core , If the current sum is negative , Then discard the previous continuous array , Start summing again
}
System.out.println(maxsums);
}
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
边栏推荐
- 利用Shap值进行异常值检测
- A collection of classic papers on convolutional neural networks (deep learning classification)
- opencv3.2 和opencv2.4安装
- LVGL 8.2 text shadow
- The failure rate is as high as 80%. What are the challenges on the way of enterprise digital transformation?
- LVGL 8.2 Draw label with gradient color
- Alcohol driving monitoring system based on stm32+ Huawei cloud IOT design
- Ultrasonic distance meter based on 51 single chip microcomputer
- 架构方面的进步
- nowcoder重排链表
猜你喜欢
![[C language] Pointer written test questions](/img/89/3d463cbbb321e45ba8342f0ddfef8f.png)
[C language] Pointer written test questions
![[MySQL from introduction to proficiency] [advanced chapter] (V) SQL statement execution process of MySQL](/img/58/a8dbed993921f372d04f7a1ee19679.png)
[MySQL from introduction to proficiency] [advanced chapter] (V) SQL statement execution process of MySQL

LVGL 8.2 Draw label with gradient color

Opencv learning notes - linear filtering: box filtering, mean filtering, Gaussian filtering

Compile oglpg-9th-edition source code with clion

【C语言】指针笔试题

失败率高达80%,企业数字化转型路上有哪些挑战?

Leetcode T48: rotating images

Gin integrated Alipay payment

Excel quickly merges multiple rows of data
随机推荐
【算法leetcode】面试题 04.03. 特定深度节点链表(多语言实现)
Leetcode t49: grouping of alphabetic words
迅为IMX6Q开发板QT系统移植tinyplay
曝光一下阿里的工资待遇和职位级别
leetcode:6109. Number of people who know the secret [definition of DP]
Query optimizer for SQL optimization
Data Lake (13): spark and iceberg integrate DDL operations
实时数据仓库
Chapter 17 process memory
C language book rental management system
Excel quickly merges multiple rows of data
第十六章 字符串本地化和消息字典(二)
商業智能BI財務分析,狹義的財務分析和廣義的財務分析有何不同?
WT588F02B-8S(C006_03)单芯片语音ic方案为智能门铃设计降本增效赋能
[cloud native] how can I compete with this database?
R language uses bwplot function in lattice package to visualize box plot and par Settings parameter custom theme mode
STM32F1与STM32CubeIDE编程实例-MAX7219驱动8位7段数码管(基于GPIO)
Test evaluation of software testing
《opencv学习笔记》-- 线性滤波:方框滤波、均值滤波、高斯滤波
ML之shap:基于boston波士顿房价回归预测数据集利用Shap值对LiR线性回归模型实现可解释性案例