leet-code/running-sum-of-1d-array/sol.rs

10 lines
220 B
Rust
Raw Normal View History

2022-06-01 13:04:19 +00:00
impl Solution {
pub fn running_sum(nums: Vec<i32>) -> Vec<i32> {
nums.iter()
.scan(0, |acc, n| {
*acc += n;
Some(*acc)
})
.collect()
}
}