From b100c7588b9fc4afae894ca1159dabb43dec2338 Mon Sep 17 00:00:00 2001 From: Matej Focko Date: Tue, 12 Jul 2022 11:32:59 +0000 Subject: [PATCH] problems: add running sum of 1D array --- problems/running-sum-of-1d-array.rs | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 problems/running-sum-of-1d-array.rs diff --git a/problems/running-sum-of-1d-array.rs b/problems/running-sum-of-1d-array.rs new file mode 100644 index 0000000..06ea638 --- /dev/null +++ b/problems/running-sum-of-1d-array.rs @@ -0,0 +1,8 @@ +impl Solution { + pub fn running_sum(nums: Vec) -> Vec { + nums.iter().scan(0, |s, &x| { + *s = *s + x; + Some(*s) + }).collect() + } +}