[leetcode]Maximum Subarray @ Python
原题地址: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
.
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的更多相关文章
- LEETCODE —— Maximum Subarray [一维DP]
Maximum Subarray Find the contiguous subarray within an array (containing at least one number) which ...
- LeetCode: Maximum Subarray 解题报告
Maximum Subarray Find the contiguous subarray within an array (containing at least one number) which ...
- [LeetCode]Maximum Subarray题解
Maximum Subarray: Find the contiguous subarray within an array (containing at least one number) whic ...
- [LeetCode] Maximum Subarray Sum
Dynamic Programming There is a nice introduction to the DP algorithm in this Wikipedia article. The ...
- 53. Maximum Subarray@python
Given an integer array nums, find the contiguous subarray (containing at least one number) which has ...
- [LeetCode] Maximum Subarray 最大子数组
Find the contiguous subarray within an array (containing at least one number) which has the largest ...
- LeetCode——Maximum Subarray
Description: Find the contiguous subarray within an array (containing at least one number) which has ...
- 53. [LeetCode] Maximum Subarray
Given an integer array nums, find the contiguous subarray (containing at least one number) which has ...
- Python3解leetcode Maximum Subarray
问题描述: Given an integer array nums, find the contiguous subarray (containing at least one number) whi ...
随机推荐
- js原型鏈與js繼承解析
最近在網上看了諸多js原型鏈的解析,說得雲裡霧裡,不明所以.徹底了解後,決定出個博客記錄一下,一是方便後來人學習,二是方便日後複習. 首先,我們來看一下構造函數.原型.實例之間的關係圖: 所以,我們通 ...
- 外键的约束(Mysql、PostgreSQL)
关于外键是什么,具体不再详述,可以自行百度. 讲一下关于外键的 On Delete和On Update的使用 最近在项目的表中看到这些,不懂顺便查了查: ONSTRAINT "c_clust ...
- android 的几个黄色警告解决办法(转)
转自:http://my.eoe.cn/864234/archive/5162.html 1:Handler 1 2 3 4 5 6 7 8 // This Handler class should ...
- VMware Workstation Pro 12 桥接联网(物理主机:Windows 7,虚拟机:CentOS 6.8)
物理主机:Windows 7,虚拟机:CentOS 6.8 1.设置虚拟机的 默认路径:编辑 -> 首选项 -> 设置“虚拟机的默认位置” 2.设置 虚拟网络:编辑 -> 虚拟网络编 ...
- TQ2440开发板存储器
TX2440A与TQ2440A开发板使用核心板完全相同 有过51单片基础的同学应该都会看懂下图,先看下图,对实验板存储器分布有一个整体印象: s3c2440存储器概述: 1.S3C2440A的存储器管 ...
- SOC 与 ARM
SOC是指片上系统,意思是一个芯片就构成一个包括了存储.CPU.甚至还有AD.UART等等其他资源的系统!而ARM只是CPU的一种,有的片上系统是51.nios.PIC.等等不一而是!特别是nios, ...
- mysql slave 主从 指定表 通配符
slave配置 slave端有可能,只复制部分表,有一些表不需要备份配置如下: 有一些表你可能做水平或则垂直的处理.如果表的前几位一样,就可以用通配符%匹配 replicate-wild-ignore ...
- Git 的 WindowsXP安装
文章1: http://blog.sina.com.cn/s/blog_5063e4c80100sqzq.html 一.安装必要客户端 1. TortoiseGit http://tortoisegi ...
- SpringBoot打jar包问题
原文:https://jingyan.baidu.com/article/6f2f55a11d6e09b5b93e6c9e.html 当你使用springBoot进行打包的时候,这篇经验会帮助到你的. ...
- 安装oracle 11g环境变量ORACLE_HOME的一个问题 转
http://blog.itpub.net/26129555/viewspace-1243467/报错内容: OUI-10137:An Oracle Home with name ORACLE_HOM ...