20240713 Finished

This commit is contained in:
jackfiled 2024-07-13 10:39:09 +08:00
parent 8b4dc6823d
commit e0d4f0c442
2 changed files with 34 additions and 1 deletions

View File

@ -171,4 +171,5 @@ mod p46_permutations;
mod p39_combination_sum; mod p39_combination_sum;
mod p22_generate_parentheses; mod p22_generate_parentheses;
mod p79_word_search; mod p79_word_search;
mod p108_convert_sorted_array_to_binary_search_tree; mod p108_convert_sorted_array_to_binary_search_tree;
mod p53_maximum_subarray;

View File

@ -0,0 +1,32 @@
/**
* [53] Maximum Subarray
*/
pub struct Solution {}
// submission codes start here
impl Solution {
pub fn max_sub_array(nums: Vec<i32>) -> i32 {
let mut pre = 0;
let mut result = nums[0];
for i in nums {
pre = i.max(pre + i);
result = result.max(pre);
}
result
}
}
// submission codes end
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_53() {
}
}