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. 非托管C++互操作

    .NET简谈互操作(一:开篇介绍) .NET简谈互操作(二:先睹为快) .NET简谈互操作(三:基础知识之DllImport特性) .NET简谈互操作(四:基础知识之Dispose非托管内存) .NE ...

  2. Vue学习三:v-on:click命令及v-html命令学习

    本文为博主原创,未经允许不得转载: 第一部分: v-on:click 命令讲解及使用方法 <!DOCTYPE html> <html lang="zh"> ...

  3. C#题目及答案(1)

    1. 简述 private. protected. public. internal 修饰符的访问权限. 答 . private : 私有成员, 在类的内部才可以访问. protected : 保护成 ...

  4. Excel 导出通用类

    public class ExportToExcelHelper { public static void ExportExcel(DataTable dt) { try { //创建一个工作簿 IW ...

  5. C++类模板和模板类

    C++ 中有一个重要特性,那就是模板类型.类似于Objective-C中的泛型.C++通过类模板来实现泛型支持. 1 基础的类模板 类模板,可以定义相同的操作,拥有不同数据类型的成员属性. 通常使用t ...

  6. rostopic demo

    发布者 #!/usr/bin/env python2. # -*- coding: utf- -*- import rospy from hdw_driver.msg import update_fi ...

  7. 学习笔记56—Endnote参考文献格式调整

    论文写作

  8. C#读取Excel表格的数据

    1.创建工程后,需要下载 EPPlus.dll 添加到工程中,这里有一个下载地址:https://download.csdn.net/download/myunity/10784634 2.下面仅实现 ...

  9. legend2---开发日志7(vue的使用场景有哪些,或者说使用的优缺点)

    legend2---开发日志7(vue的使用场景有哪些,或者说使用的优缺点) 一.总结 一句话总结:任何页面都可以使用vue,尤其是有交互的或者用ajax的,但是vue插件及其它各种插件加载需要时间, ...

  10. DNA sequence open reading frames (ORFs) | DNA序列的开放阅读框ORF预测

    常见的ORF预测工具 Open Reading Frame Finder- NCBI ORF Finder - SMS OrfPredictor  - YSU 基本概念 开放阅读框(英语:Open r ...