From 1ff27f159adddfddc0d81d34043e13a4249f48e8 Mon Sep 17 00:00:00 2001 From: Gleb Koval Date: Wed, 1 Jun 2022 14:04:19 +0100 Subject: [PATCH] running-sum-of-1d-array --- running-sum-of-1d-array/sol.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 running-sum-of-1d-array/sol.rs diff --git a/running-sum-of-1d-array/sol.rs b/running-sum-of-1d-array/sol.rs new file mode 100644 index 0000000..0aa1436 --- /dev/null +++ b/running-sum-of-1d-array/sol.rs @@ -0,0 +1,10 @@ +impl Solution { + pub fn running_sum(nums: Vec) -> Vec { + nums.iter() + .scan(0, |acc, n| { + *acc += n; + Some(*acc) + }) + .collect() + } +} \ No newline at end of file