leet-code/maximum-subarray/sol.rs

10 lines
263 B
Rust
Raw Normal View History

2022-05-29 19:21:38 +00:00
impl Solution {
pub fn max_sub_array(nums: Vec<i32>) -> i32 {
nums.iter()
.fold((nums[0], 0), |(max, sum), n| {
let new_sum = sum + n;
(max.max(new_sum), 0.max(new_sum))
})
.0
}
}