Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- long long zeroFilledSubarray(vector<int>& nums) {
- long long sum=0;
- vector<long long> v;
- int c=0;
- for(int i=0;i<nums.size();i++)
- {
- if(nums[i]==0)
- {
- c++;
- }
- else
- {
- if(v.size()==0 && c==0)
- {
- continue;
- }
- v.push_back(c);
- c=0;
- }
- }
- if(nums[nums.size()-1]==0)
- {
- v.push_back(c);
- }
- for(int i=0;i<v.size();i++)
- {
- sum+=((v[i])*(v[i]+1))/2;
- }
- return sum;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment