problem

MaximumSubarray

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的更多相关文章

  1. 【Leetcode】53. Maximum Subarray

    题目地址: https://leetcode.com/problems/maximum-subarray/description/ 题目描述: 经典的求最大连续子数组之和. 解法: 遍历这个vecto ...

  2. 【LeetCode】53. Maximum Subarray 最大子序和 解题报告(Python & C++ & Java)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 暴力解法 动态规划 日期 题目地址: https:/ ...

  3. 【LEETCODE】53、数组分类,简单级别,题目:989、674、1018、724、840、747

    真的感觉有点难... 这还是简单级别... 我也是醉了 package y2019.Algorithm.array; import java.math.BigDecimal; import java. ...

  4. 【LeetCode】53. Maximum Subarray (2 solutions)

    Maximum Subarray Find the contiguous subarray within an array (containing at least one number) which ...

  5. 【LeetCode】53.最大子序和

    最大子序和 给定一个整数数组 nums ,找到一个具有最大和的连续子数组(子数组最少包含一个元素),返回其最大和. 示例: 输入: [-2,1,-3,4,-1,2,1,-5,4], 输出: 6 解释: ...

  6. 53. Maximum Subarray【leetcode】

    53. Maximum Subarray[leetcode] Find the contiguous subarray within an array (containing at least one ...

  7. 【LeetCode】640. Solve the Equation 解题报告(Python)

    [LeetCode]640. Solve the Equation 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博客: ht ...

  8. 【LeetCode】Minimum Depth of Binary Tree 二叉树的最小深度 java

    [LeetCode]Minimum Depth of Binary Tree Given a binary tree, find its minimum depth. The minimum dept ...

  9. 【Leetcode】Pascal&#39;s Triangle II

    Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3, Return [1,3 ...

  10. 27. Remove Element【leetcode】

    27. Remove Element[leetcode] Given an array and a value, remove all instances of that value in place ...

随机推荐

  1. KM算法详解[转]

    KM算法详解 原帖链接:http://www.cnblogs.com/zpfbuaa/p/7218607.html#_label0 阅读目录 二分图博客推荐 匈牙利算法步骤 匈牙利算法博客推荐 KM算 ...

  2. 二十、MVC的WEB框架(Spring MVC)

    一.Spring MVC 运行原理:客户端请求提交到DispatcherServlet,由DispatcherServlet控制器查询HandlerMapping,找到并分发到指定的Controlle ...

  3. Const的使用

    const意味为readonly,即只读,const可被施加于任何作用域内的对象,函数参数,函数返回类型,成员函数本体 使用: const修饰变量时本质是 const在谁后面谁就不可修改,const在 ...

  4. ueeditor 百度编译器使用onchange效果

    <script id="editor" type="text/plain" style="width:100%;height:200px;&qu ...

  5. react router @4 和 vue路由 详解(二)react-router @4用法

    完整版:https://www.cnblogs.com/yangyangxxb/p/10066650.html 2.react-router @4用法 a.大概目录      不需要像vue那样麻烦的 ...

  6. 架构之路:nginx与IIS服务器搭建集群实现负载均衡(一)

    最近亮亮在研究IIS的负载均衡!本人由于初出茅庐,防骗意识薄弱,一不小心被亮亮坑上了IIS负载均衡之路(亮亮是真黑哈!).前车之鉴啊!小伙伴们要小心.不过既上了贼船,便决定一条道走到黑.于是乎从大前天 ...

  7. python之路 ---计算机硬件基础

    计算机(computer)俗称电脑,是现代一种用于高速计算的电子计算机器,可以进行数值计算,又可以进行逻辑计算,还具有存储记忆功能.是能够按照程序运行,自动.高速处理海量数据的现代化智能电子设备.一个 ...

  8. Cracking The Coding Interview 1.4

    //Write a method to decide if two strings are anagrams or not. // // 变位词(anagrams)指的是组成两个单词的字符相同,但位置 ...

  9. 深入理解java虚拟机---对象的结构(九)

    注意: 我们可以看到的就是InstanceData的数据. 先转载一篇文章作为开头,因为讲的非常详细,我就简单加工下放到这里: 对象结构 在HotSpot虚拟机中,对象在内存中存储的布局可以分为3块区 ...

  10. HDU 2602 Bone Collectors(背包问题,模版)

    Bone Collector Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...