在一个数组中找出和最大的一个连续的子数组串
来源:互联网 发布:淘宝银座365是正品吗 编辑:程序博客网 时间:2024/06/05 00:03
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace ConsoleApplication11{ class Program { static void Main(string[] args) { //int[] a =new int[]{1,-2,3,5,-4, 3, 0, -1}; //int[] a = new int[] { -1, -2, -3, -5, -4, -3, -10, -1 }; FindMaxSumInString2(); } public static void FindMaxSumInString2() { //int[] a = new int[] { 31, -41, 59, 26, -53, 58, 97, -93, -23, 84 }; int[] a = new int[] { -1, -2, -3, -5, -4, -3, -10, -1 }; int sum = int.MinValue; int tempSum = 0; for (int i = 0; i < a.Length; i++) { //old sum is <=0; ignore it. if (tempSum > 0) { tempSum = tempSum + a[i]; } else { tempSum = a[i]; } if (tempSum > sum) { sum = tempSum; } } Console.WriteLine(sum); } public void FindMaxSumInString() { //int[] a = new int[] { 31, -41, 59, 26, -53, 58, 97, -93, -23, 84 }; int[] a = new int[] { -1, -2, -3, -5, -4, -3, -10, -1 }; int sum = int.MinValue; int tempSum = 0; for (int i = 0; i < a.Length; i++) { for (int j = i; j < a.Length; j++) { tempSum = tempSum + a[j]; if (tempSum > sum) { sum = tempSum; Console.WriteLine("start: " + i); Console.WriteLine("end: " + j); } } tempSum = 0; } Console.WriteLine(sum); } } }
0 0
- 在一个数组中找出和最大的一个连续的子数组串
- 求一个数组中连续子数组的最大和
- 一个数组中找出连续子向量的最大和 分治算法 扫描算法O(n)
- 给定一个数组,找出这个和最大的连续子数组的和
- 找出连续子数组的最大和
- 一个正负数组,求其最大的连续子串和
- 求一个数组中连续子数组的最大乘积
- 找出一个数组里边和最大的子数组,输出最大和和子数组
- 在一个数组中找到连续的子数组最大的乘积
- 在一个数列中找出最大和的连续子列
- 找出数组和最大的连续子序列
- 找出两个不相交连续子数组的最大和
- 给定一个二进制数组,找到一个连续的0和1相等的最大子数组。
- 一个数组中和最大的连续子数组
- 一个包含正整数和负整数的数组,找出和最大的子串.
- 小菜鸟请求各位大大帮忙在一个字符数组中,找出最长连续重复的字符子序列
- 数组中连续子数组的和的最大和
- 求一个整形数组的和最大的连续子串 -------- 程序员面试金典
- JavaScript 函数
- 二维数组转化为一唯数组
- GoogleCloudMessage推送的使用一(申请)
- maven引入本地jar包
- 【转载】怎样把Oracle的数据导入到SQLServer2005中
- 在一个数组中找出和最大的一个连续的子数组串
- 实现自定义水波纹效果
- AEAI CRM_v1.5.2升级说明,开源客户关系管理系统
- ION基本概念介绍和原理分析
- UIColor
- 把数据保存到数据库附加表 `dede_addonarticle` 时出错,请把相关信息提交给DedeCms
- SpringMVC实现angularjs图片上传
- 以太网基础知识0(UDP和TCP有什么区别)
- Properties文件的读取。