Here I post a way to solve maximum sub array problem:

The problem described like this: here is an array like [1,4,5,32,4,8,7,1,23,88], we should find a sub array such that the difference between tail and head of the sub array is maximum.

def getMaxSubarray(ls):
a,b = ls[],ls[]
ixl,ixr = ,
summ =
for i in range(,len(ls)):
if ls[i] > b:
b = ls[i]
ixr = i
#print 'b: ',b,'and bix: ',ixr
if ls[i] < a:
summ2 = b - a
if summ2>summ:
summ = summ2
fixl = ixl
fixr = ixr
a = ls[i]
b = ls[i]
ixl = i
ixr = i
#print 'a: ',a,' and ax: ',ixl,' and b: ',b,' and bx: ',ixr
if (b - a) > summ:
summ = b-a
fixl = ixl
fixr = ixr
return(fixl,fixr,summ) ls = [,,,8.5,10.5,10.2,6.7,10.1,9.4,10.6,11.2,,,,,6.8,,10.1,7.9,9.3,,9.7]
getMaxSubarray(ls)

Maximum sub array的更多相关文章

  1. 164. Maximum Gap (Array; sort)

    Given an unsorted array, find the maximum difference between the successive elements in its sorted f ...

  2. Maximum Gap (ARRAY - SORT)

    QUESTION Given an unsorted array, find the maximum difference between the successive elements in its ...

  3. 53. Maximum Subarray (Array; DP)

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

  4. 《量化投资:以MATLAB为工具》连载(1)基础篇-N分钟学会MATLAB(上)

    http://blog.sina.com.cn/s/blog_4cf8aad30102uylf.html <量化投资:以MATLAB为工具>连载(1)基础篇-N分钟学会MATLAB(上) ...

  5. UFLDL实验报告1: Softmax Regression

    PS:这些是今年4月份,跟斯坦福UFLDL教程时的实验报告,当时就应该好好整理的…留到现在好凌乱了 Softmax Regression实验报告 1.Softmax Regression实验描述 So ...

  6. MATLAB学习之内存溢出的管理方法

    今天用Matlab跑程序,由于数据量太大,又出现 Out of memory. Type HELP MEMORY for your options.的问题.看到这篇文章非常实用,转过来方便查阅~ 用 ...

  7. win7 32位解决matlab out of memory问题

    由于最近在做DL,matlab load数据时由于内存只有2G,会出现out of memory的情况,网上百度了下都是在xp下打开3GB来解决该问题,但是由于win7没有boot.ini无法在win ...

  8. [LeetCode] Maximum XOR of Two Numbers in an Array 数组中异或值最大的两个数字

    Given a non-empty array of numbers, a0, a1, a2, … , an-1, where 0 ≤ ai < 231. Find the maximum re ...

  9. Leetcode: Maximum XOR of Two Numbers in an Array

    Given a non-empty array of numbers, a0, a1, a2, - , an-1, where 0 ≤ ai < 231. Find the maximum re ...

随机推荐

  1. ESP8266 使用

    ESP8266 微机使用串口和ESP8266建立通信,ESP8266把消息通过wifi发送出去 助手软件 网络调试助手 串口调试助手 AT指令 指令 作用 AT 测试是否进入AT模式 AT+RST 重 ...

  2. 一个 xxx is not defined 引发的爬坑之路

    出处 https://www.cnblogs.com/daysme/ - 2018-01-06 昨晚找了一个代码解决了我对配置的需求.高兴的拿到手机上测试却发现点击没有效果,电脑上是可以的呀,电脑上的 ...

  3. 【译】第18节---数据注解-ForeignKey

    原文:http://www.entityframeworktutorial.net/code-first/foreignkey-dataannotations-attribute-in-code-fi ...

  4. java web 工程更改名字

    如图: 将工程名字struts2Project02更改为struts2Project03,步骤如下: 1. 右键工程名字,选中properties,如图 2.更改项目名字 3.第2步已经真正把项目名字 ...

  5. MySql查询功能梳理

    CREATE DATABASE CristinMysql Create table employee( eId int(9) not null auto_increment, eName varcha ...

  6. Git 中 pull 和 clone 的区别

    git pull git clone clone 是本地没有 repository 时,将远程 repository 整个下载过来. pull 是本地有 repository 时,将远程 reposi ...

  7. Windows下及Mac下的IntelliJ IDEA快捷键

    Mac 键盘符号说明 ⌘ == Command ⇧ == Shift ⇪ == Caps Lock ⌥ == Option ⌃ == Control ↩ == Return/Enter ⌫ == De ...

  8. VC.时间_ZC测试代码

    1. #include <windows.h> #include <stdio.h> void TimeNowZ( char* _pc ) { SYSTEMTIME sys; ...

  9. leecode第一百三十六题(只出现一次的数字)

    class Solution { public: int singleNumber(vector<int>& nums) { int len=nums.size(); ; ;i&l ...

  10. node+ts的心得与坑

    首先先明确,用node+ts的目的,为什么不ng+ts.这一点后面还会反复提醒自己 node毕竟不是ng. 用node的理由: 处理js,在后端操纵dom,读写类html格式的东西,比直接用py的后端 ...