1
0
Fork 0
mirror of https://gitlab.com/mfocko/LeetCode.git synced 2024-09-19 01:36:57 +02:00

problems: add running sum of 1D array

This commit is contained in:
Matej Focko 2022-07-12 11:32:59 +00:00
parent 2a40331d5d
commit b100c7588b

View 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()
}
}