子序列求和最大值之javascript实现
2011-10-29 20:08
295 查看
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>无标题文档</title> </head> <body> <script type="text/javascript"> var list = [4,2,1,-2,10,90,40,-93,-1,8,70]; function subSeqMax(a){ var tempMax =0; var currMax =0; for(var i=0;i<a.length;i++){ for(var j=i;j<a.length;j++){ tempMax =addTo(i,j,a); if(tempMax>currMax){ currMax = tempMax; } } } return currMax; } function addTo(start,end,a){ var tempMax =0; var currMax =0; while(start<=end){ tempMax +=a[start++]; if(tempMax>currMax){ currMax = tempMax;//如果比储存的值大,就刷新之; } } return currMax; } alert(subSeqMax(list)); //addTo(0,list.length-1,list) </script> </body> </html>
相关文章推荐
- 最大空间序列 C语言实现
- awk实现求和、平均、最大值和最小值的计算操作
- “最长上升子序列,最大连续子序列和,最长公共子串”的Java实现
- 最大子序列分治实现以及改进
- 最大子序列求和
- 找出数组中最长的连续数字序列(JavaScript实现)
- 01 最大子序列求和
- 逆转序列的递归/尾递归(+destructuring assignment)实现(JavaScript + ES6)
- 最大子序列求和问题
- MapReduce功能实现六---最大值(Max)、求和(Sum)、平均值(Avg)
- 【算法数据结构Java实现】时间复杂度为O(n)的最大和序列
- 能不能用javascript实现素数求和问题呢?
- 算法之最大子序列求和
- 求和为n连续正数序列 C++实现
- javascript实现自动求和
- javascript实现求和
- 最大子序列和的四种不同复杂度实现
- 最大连续子序列求和详解
- 最大堆、索引堆、二叉搜索树的JavaScript实现
- 最大子序列的求解分析(java代码实现)