原题地址: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. Redis高可用之主从复制实践(四)

    0.Redis目录结构 1)Redis介绍及部署在CentOS7上(一) 2)Redis指令与数据结构(二) 3)Redis客户端连接以及持久化数据(三) 4)Redis高可用之主从复制实践(四) 5 ...

  2. webview知多少?

    原生页面不会用到webview,html页面内嵌APP,才会用到webview. 一.什么是webview?WebView是手机中内置了一款高性能 webkit 内核浏览器,在 SDK 中封装的一个组 ...

  3. [HDU4348]To the moon(主席树+标记永久化)

    学可持久化treap的时候才发现自己竟然没写过需要标记下传的主席树,然而现在发现大部分操作都可以标记永久化,下传会增大占用空间. 这题一种写法是和普通的线段树一样标记下传,注意所有修改操作(包括put ...

  4. yum与apt命令比较,yum安装出现No package vim available解决办法

    yum (Yellowdog Updater Modified)是一个集与查找,安装,更新和删除程序的Linux软件.它运行在RPM包兼容的Linux发行版本上,如:RedHat, Fedora, S ...

  5. notepad++ 如何选择10000行-20000行之间的文本?

    最近要上传导入一批数据,但是数据太多,一次上传不了,所以就要分批上传,而且数据全部在一个txt里面,这时就想一次复制一部分出来导入,直到导入完成,但是问题来了,数据太多,选择1到10000行,鼠标要拉 ...

  6. .Net 环境下C# 通过托管C++调用本地C++ Dll文件

     综述 : 本文章介绍.Net 环境下C# 通过托管C++调用本地C++ Dll文件, 示例环境为:VS2010, .Net4.0, Win7. 具体事例为测试C++, C#, 及C#调用本地C++D ...

  7. linux网络编程:splice函数和tee( )函数高效的零拷贝

    splice( )函数 在两个文件描述符之间移动数据,同sendfile( )函数一样,也是零拷贝. 函数原型: #include <fcntl.h> ssize_t splice(int ...

  8. TextAppearance.Material.Widget.Button.Inverse,Widget.Material.Button.Colored

    编译xamarin android项目报错: android:TextAppearance.Material.Widget.Button.Inverse android:Widget.Material ...

  9. Xamarin.Forms.Xaml.XamlParseException: MarkupExtension not found for trans:Translate using a PCL in Release Mode

    I'm pretty desperate finding the solution for the problem stated below. I have a cross platform solu ...

  10. IIS日志文件清理

    如何清除IIS日志以释放空间 打开“我的电脑”发现10GB容量的C盘只剩余355MB“可用空间”,已经严重不够用.如下图: 如果服务器的管理员并没有在C盘存储大容量文件,而IIS中站点的访问量又非常大 ...