20240713 Finished
This commit is contained in:
parent
8b4dc6823d
commit
e0d4f0c442
|
@ -171,4 +171,5 @@ mod p46_permutations;
|
|||
mod p39_combination_sum;
|
||||
mod p22_generate_parentheses;
|
||||
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;
|
32
src/problem/p53_maximum_subarray.rs
Normal file
32
src/problem/p53_maximum_subarray.rs
Normal 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() {
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user