Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,19 @@
|
|||
fn main() {
|
||||
let nums = [1,2,39,34,20, -20, -16, 35, 0];
|
||||
|
||||
let mut max = 0;
|
||||
let mut boundaries = 0..0;
|
||||
|
||||
for length in 0..nums.len() {
|
||||
for start in 0..nums.len()-length {
|
||||
let sum = (&nums[start..start+length]).iter()
|
||||
.fold(0, |sum, elem| sum+elem);
|
||||
if sum > max {
|
||||
max = sum;
|
||||
boundaries = start..start+length;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
println!("Max subsequence sum: {} for {:?}", max, &nums[boundaries]);;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue