Skip to content

Instantly share code, notes, and snippets.

View Moshekwa's full-sized avatar

Moshekwa Moshekwa

View GitHub Profile
@phillco
phillco / maxSubarray.groovy
Created February 6, 2012 21:42
Maximum subarray algorithm
/**
* Uses a smart, O(n) function to find the maximum subarray.
*/
def find_max_subarray_smart( array ) {
int max, max_start, max_end, start, tentative = 0;
for ( int i = 0; i < array.size(); i++ ) {
tentative += array[i];