foo.md
· 959 B · Markdown
Ham
this is me testing opengist
here is some rust code
```rs
use std::cmp;
impl Solution {
pub fn max_sub_array(nums: Vec<i32>) -> i32 {
let mut current_subarray_sum = nums[0];
let mut max_subarray_sum = nums[0];
for num in &nums[1..] {
let num = *num;
// as we iterate through the array,
// we increment by the next number in the "current" subarray
// if we find that the sum of the current subarray is less
// than the current number, we "reset" to the current number
current_subarray_sum = cmp::max(
num,
current_subarray_sum + num
);
// meanwhile, always be keeping track of the max subarray sum
// we've found
max_subarray_sum = cmp::max(
max_subarray_sum,
current_subarray_sum
);
}
max_subarray_sum
}
}
```
this is me testing opengist
here is some rust code
use std::cmp;
impl Solution {
pub fn max_sub_array(nums: Vec<i32>) -> i32 {
let mut current_subarray_sum = nums[0];
let mut max_subarray_sum = nums[0];
for num in &nums[1..] {
let num = *num;
// as we iterate through the array,
// we increment by the next number in the "current" subarray
// if we find that the sum of the current subarray is less
// than the current number, we "reset" to the current number
current_subarray_sum = cmp::max(
num,
current_subarray_sum + num
);
// meanwhile, always be keeping track of the max subarray sum
// we've found
max_subarray_sum = cmp::max(
max_subarray_sum,
current_subarray_sum
);
}
max_subarray_sum
}
}