当前位置:网站首页>Topic36——53. Maximum subarray and
Topic36——53. Maximum subarray and
2022-06-26 00:03:00 【_ Cabbage_】
subject : Give you an array of integers nums , Please find a continuous subarray with the largest sum ( A subarray contains at least one element ), Return to its maximum and .
Subarray Is a continuous part of the array .
Example 1:
Input :nums = [-2,1,-3,4,-1,2,1,-5,4]
Output :6
explain : Continuous subarray [4,-1,2,1] And the biggest , by 6 .
Example 2:
Input :nums = [1]
Output :1
Example 3:
Input :nums = [5,4,-1,7,8]
Output :23
Tips :
1 <= nums.length <= 105
-104 <= nums[i] <= 104
Dynamic programming :
class Solution {
public int maxSubArray(int[] nums) {
int max = nums[0];
int pre = 0;
for(int j = 0; j < nums.length; j++) {
pre = Math.max(nums[j], nums[j] + pre);
max = Math.max(max, pre);
}
return max;
}
}
边栏推荐
- static关键字详解
- ValueError: color kwarg must have one color per data set. 9 data sets and 1 colors were provided解决
- The InputStream stream has been closed, but the file or folder cannot be deleted, indicating that it is occupied by the JVM
- final和static
- Object array de duplication
- 【微信公众号H5】 生成带参数进入公众号关注页的二维码 监听用户关注公众号事件 自定义菜单栏 (服务端)
- php中使用google protobuf协议环境配置
- 懒人教你用猕猴桃一月饱减16斤_过路老熊_新浪博客
- Mutual conversion of float type data and datetime type data in sqlserver2008
- 支付宝支付接口沙箱环境测试以及整合到一个ssm电商项目中
猜你喜欢

Use Baidu map API to set an overlay (infowindow) in the map to customize the window content

WINCC与STEP7的仿真连接_过路老熊_新浪博客

Final and static

Unable to start debugging. Unexpected GDB output from command “-environment -cd xxx“ No such file or

今天说说String相关知识点

Establishment of multiple background blocks in botu software_ Old bear passing by_ Sina blog

推荐系统设计

js实现输入开始时间和结束时间,输出其中包含多少个季,并且把对应年月打印出来

7.常用指令(下)v-on,v-bind,v-model的常见操作

iomanip头文件在实战中的作用
随机推荐
Search rotation array ii[Abstract dichotomy exercise]
PHP interprocess pass file descriptor
使用百度地图API在地图中设置一个覆盖物(InfoWindow),可自定义窗口内容
西门子S7-200PLC和丹佛斯变频器的通讯协议改造_过路老熊_新浪博客
unsigned与signed之大白话
Two ways to center block level elements
MySQL InnoDB lock knowledge points
line-height小用
Reading notes on how to connect the network - hubs, routers and routers (III)
Format the number. If the number is not enough, fill in 0, for example, 1:0001,25:0025
Talk about the copy on write mechanism of PHP variables or parameters
Object类常用方法
Stop eating vitamin C tablets. These six fruits have the highest vitamin C content
Sword finger offer 48 Longest substring without duplicate characters
记录一些cf的题
对象数组去重
记录一下刷LeetCode瞬间有思路的一道简单题——剑指 Offer 09. 用两个栈实现队列
Oracle writes a trigger that inserts a piece of data first and updates a field in the data
详解synchronize关键字
Studio5k v28安装及破解_过路老熊_新浪博客