From 3a30051745f4bd76b27511bab08c4e0997dfc433 Mon Sep 17 00:00:00 2001 From: wisdompeak Date: Fri, 20 May 2022 23:33:14 -0700 Subject: [PATCH] Create 930.Binary-Subarrays-With-Sum_v2.cpp --- .../930.Binary-Subarrays-With-Sum_v2.cpp | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 Hash/930.Binary-Subarrays-With-Sum/930.Binary-Subarrays-With-Sum_v2.cpp diff --git a/Hash/930.Binary-Subarrays-With-Sum/930.Binary-Subarrays-With-Sum_v2.cpp b/Hash/930.Binary-Subarrays-With-Sum/930.Binary-Subarrays-With-Sum_v2.cpp new file mode 100644 index 000000000..78bd1e41c --- /dev/null +++ b/Hash/930.Binary-Subarrays-With-Sum/930.Binary-Subarrays-With-Sum_v2.cpp @@ -0,0 +1,34 @@ +class Solution { +public: + int numSubarraysWithSum(vector& A, int S) + { + int n = A.size(); + vectorpostZeros(n); + int count = 0; + for (int i=n-1; i>=0; i--) + { + postZeros[i] = count; + if (A[i]==0) + count++; + else + count = 0; + } + + int j = 0, sum = 0; + int ret = 0; + for (int i=0; i