原题地址:https://oj.leetcode.com/problems/maximum-subarray/

题意:

Find the contiguous subarray within an array (containing at least one number) which has the largest sum.

For example, given the array [−2,1,−3,4,−1,2,1,−5,4],
the contiguous subarray [4,−1,2,1] has the largest sum = 6.

click to show more practice.

More practice:

If you have figured out the O(n) solution, try coding another solution using the divide and conquer approach, which is more subtle.

解题思路:最大子序列和问题,直接上代码,不是我能想出来的。
代码:
class Solution:
# @param A, a list of integers
# @return an integer
def maxSubArray(self, A):
ThisSum = 0
MaxSum = -10000 for i in range( 0, len(A) ):
if ThisSum < 0:
ThisSum = 0
ThisSum = ThisSum + A[ i ]
MaxSum = max( ThisSum, MaxSum ) return MaxSum

[leetcode]Maximum Subarray @ Python的更多相关文章

  1. LEETCODE —— Maximum Subarray [一维DP]

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

  2. LeetCode: Maximum Subarray 解题报告

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

  3. [LeetCode]Maximum Subarray题解

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

  4. [LeetCode] Maximum Subarray Sum

    Dynamic Programming There is a nice introduction to the DP algorithm in this Wikipedia article. The ...

  5. 53. Maximum Subarray@python

    Given an integer array nums, find the contiguous subarray (containing at least one number) which has ...

  6. [LeetCode] Maximum Subarray 最大子数组

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

  7. LeetCode——Maximum Subarray

    Description: Find the contiguous subarray within an array (containing at least one number) which has ...

  8. 53. [LeetCode] Maximum Subarray

    Given an integer array nums, find the contiguous subarray (containing at least one number) which has ...

  9. Python3解leetcode Maximum Subarray

    问题描述: Given an integer array nums, find the contiguous subarray (containing at least one number) whi ...

随机推荐

  1. android 手机不能断点

    一个安卓平板 型号 联想 .. ,用andriod studio 打断点 调试, 应用 就卡死2秒,然后就挂掉了.  不知如何解决.

  2. usb3.0 monitor is already started

    用360 开机加速里找到这个程序,把它从开机启动中删除掉就好.

  3. BZOJ.3004.[SDOI2012]吊灯(结论)

    题目链接 BZOJ 洛谷 题意: 将树划分为k个连通块,要求每个连通块大小相同.输出可能的大小. 结论: 满足条件时颜色的连通块数为k,当且仅当有 \(n/k\) 个节点满足它的子树是k的倍数(显然还 ...

  4. POP3_收取QQ邮箱邮件的问题

    今天纠结了一天的时间,使用pop3协议收取qq邮箱中邮件时,因为一个特别坑爹的问题重新写n次,最后发现是因为qq邮箱设置了独立邮箱密码,必须的用独立邮箱密码登陆才行,/(ㄒoㄒ)/~~!!!! 但今天 ...

  5. java之ibatis数据缓存

    使用IBatis作数据缓存 1.SqlMapConfig.xml中<settingscacheModelsEnabled="true" //设置为trueenhancemen ...

  6. LPC43xx双核笔记

    简介本页提供了一些使用LPC43xx器件双核特性的基本信息.此页面上的信息和专题使用Keil uVision4工具,以双核工程的使用来演示.该工程初始化两个内核以运行FreeRTOS,并采用三色LED ...

  7. sTM32 使用TIMx_CH1作为 Tx1F_ED 计数器时钟

    环境:iar arm 5.3 stm32f103vbt6 使用PA.8 外部输入10Mhz的方波.可从systick中断得到数据4. 4×5000(预分频值)×1000(tick中断时间)=20MHz ...

  8. [EF Core]数据迁移(二)

    摘要 在实际项目中,大多都需要对业务逻辑以及操作数据库的逻辑进行分成操作,这个时候该如何进行数据的迁移呢? 步骤 上篇文章:EF Core数据迁移操作 比如,我们将数据上下文放在了Data层. 看一下 ...

  9. Snmp学习总结(五)——WindowsServer2008安装和配置SNMP

    一.安装SNMP 在Windows Server 2008以及Windows Server 2008 R2中,SNMP是以一个服务器功能的形式存在的,SNMP的安装步骤如下所示: 1.打开[开始]→[ ...

  10. 安装oracle10g“程序异常终止。发生内部错误。请将以下文件提供给oracle技术支持部门

    发生情景:测试环境搭建的是windows 2008 r2 sp1系统 在安装Oracle 10g数据库时发生了错误,现在把解决问题的方法和原因分享给大家. *  安装出现的现象: 输入完密码后下一步时 ...