Crate max_subarray_sum[−][src]
Expand description
max_subarray_sum
Finds maximum subarray sum in a Vec<i32>
. This is also
known as max sum contigious subarray. If there are multiple
such subarrays, only the one that comes first is selected.
The algorithm has time complexity of O(N)
and space complexity
of O(1)
.
Quick Start
use max_subarray_sum::Elements; let mut list: Vec<i32> = vec![-2, -3, 4, -1, -2, 1, 5, -3]; let len: usize = list.len(); let mut elements = Elements::new(&mut list, len); let max_sum: i32 = elements.find_max_sum().result(); assert_eq!(7, max_sum);
Structs
The Elements
struct holds the list and related pieces of informations
of it.