mirror of
https://gitlab.com/mfocko/LeetCode.git
synced 2024-11-09 15:59:06 +01:00
problems: add running sum of 1D array
This commit is contained in:
parent
2a40331d5d
commit
b100c7588b
1 changed files with 8 additions and 0 deletions
8
problems/running-sum-of-1d-array.rs
Normal file
8
problems/running-sum-of-1d-array.rs
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
impl Solution {
|
||||||
|
pub fn running_sum(nums: Vec<i32>) -> Vec<i32> {
|
||||||
|
nums.iter().scan(0, |s, &x| {
|
||||||
|
*s = *s + x;
|
||||||
|
Some(*s)
|
||||||
|
}).collect()
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue