【leetcode】53-MaximumSubarray
problem
code
class Solution {
public:
int maxSubArray(vector<int>& nums) {
int max = INT_MIN;
int sum = ;
for(size_t i=; i<nums.size(); i++)
{
sum = nums[i];
if(sum>max) max = sum;//err.
for(size_t j=i+; j<nums.size(); j++)
{
sum += nums[j];
if(sum>max) max = sum;
}
}
return max;
}
};
参考
1.
https://leetcode.com/problems/maximum-subarray/description/
完
【leetcode】53-MaximumSubarray的更多相关文章
- 【Leetcode】53. Maximum Subarray
题目地址: https://leetcode.com/problems/maximum-subarray/description/ 题目描述: 经典的求最大连续子数组之和. 解法: 遍历这个vecto ...
- 【LeetCode】53. Maximum Subarray 最大子序和 解题报告(Python & C++ & Java)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 暴力解法 动态规划 日期 题目地址: https:/ ...
- 【LEETCODE】53、数组分类,简单级别,题目:989、674、1018、724、840、747
真的感觉有点难... 这还是简单级别... 我也是醉了 package y2019.Algorithm.array; import java.math.BigDecimal; import java. ...
- 【LeetCode】53. Maximum Subarray (2 solutions)
Maximum Subarray Find the contiguous subarray within an array (containing at least one number) which ...
- 【LeetCode】53.最大子序和
最大子序和 给定一个整数数组 nums ,找到一个具有最大和的连续子数组(子数组最少包含一个元素),返回其最大和. 示例: 输入: [-2,1,-3,4,-1,2,1,-5,4], 输出: 6 解释: ...
- 53. Maximum Subarray【leetcode】
53. Maximum Subarray[leetcode] Find the contiguous subarray within an array (containing at least one ...
- 【LeetCode】640. Solve the Equation 解题报告(Python)
[LeetCode]640. Solve the Equation 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博客: ht ...
- 【LeetCode】Minimum Depth of Binary Tree 二叉树的最小深度 java
[LeetCode]Minimum Depth of Binary Tree Given a binary tree, find its minimum depth. The minimum dept ...
- 【Leetcode】Pascal's Triangle II
Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3, Return [1,3 ...
- 27. Remove Element【leetcode】
27. Remove Element[leetcode] Given an array and a value, remove all instances of that value in place ...
随机推荐
- az nginx install and other
Nginx 1◆ nginx install 源码:https://trac.nginx.org/nginx/browser 官网:http://www.nginx.org/ ...
- coursera国际法笔记 持续更新
LECTURE ONE International crime court(ICC) came into being after the Second World War. The Nuremberg ...
- 为什么IT运维工程师要学习Linux系统
不论你是否知道,其实你每天都在使用Linux.每次你访问微博.百度甚至是一些小电影网站,你的客户端(浏览器)都在与运行在Linux系统上的服务端程序进行通讯,大多数的电子设备,例如数位录像机.飞机.自 ...
- flask-security(一)快速入门
很多例程都是基于flask-sqlalchemy的. 但是我使用sqlalchemy,并没有使用sqlalchemy,看中的也就是flask的灵活性. 暂时写flask的程序,但是为了以后写别的程序方 ...
- vue-12-渲染函数 & JSX
render() Vue.component('anchored-heading', { render: function (createElement) { return createElement ...
- js call回调的this指向问题
function fn1(){ console.log(1); } function fn2(){ console.log(2); } fn1.call(fn2); //输出 1 fn1.call.c ...
- Cracking The Coding Interview 9.3
//Given a sorted array of n integers that has been rotated an unknown number of times, give an O(log ...
- HTML5触摸事件(touchstart、touchmove和touchend)
HTML5中新添加了很多事件,但是由于他们的兼容问题不是很理想,应用实战性不是太强,所以在这里基本省略,咱们只分享应用广泛兼容不错的事件,日后随着兼容情况提升以后再陆续添加分享.今天为大家介绍的事 ...
- c#dataGridView 知识
一.单元格内容的操作 // 取得当前单元格内容 Console.WriteLine(DataGridView1.CurrentCell.Value); // 取得当前单元格的列 Index Conso ...
- uiautomator2 获取APP Toast内容
前言:appium必须是1.6以上的版本 环境(安装和安装都可以运行成功,我也不确定要不要这个): 1.抓到toast需要安装uiautomator2,安装npm:npm install -g cnp ...