running-sum-of-1d-array

This commit is contained in:
Gleb Koval 2022-06-01 14:04:19 +01:00
parent 0bcf0977cf
commit 1ff27f159a
Signed by: cyclane
GPG Key ID: 15E168A8B332382C
1 changed files with 10 additions and 0 deletions

View File

@ -0,0 +1,10 @@
impl Solution {
pub fn running_sum(nums: Vec<i32>) -> Vec<i32> {
nums.iter()
.scan(0, |acc, n| {
*acc += n;
Some(*acc)
})
.collect()
}
}