标签:c style class blog code java
/** * 最大子数组的暴力求解算法,复杂度为o(n2) * @param n * @return */ static MaxSubarray findMaxSubarraySlower(int[] n) { long tempSum = 0; int left = 0; int right = 0; long sum = Long.MIN_VALUE; for (int i = 0; i < n.length; i++) { for (int j = i; j < n.length; j++) { tempSum += n[j]; if (tempSum > sum) { left = i; right = j; sum = tempSum; } } tempSum = 0; } return new MaxSubarray(left, right, sum); }
第四章 分治策略 4.1 最大子数组问题 (暴力求解算法),布布扣,bubuko.com
标签:c style class blog code java
原文地址:http://www.cnblogs.com/xiaojintao/p/3774873.html