Skip to content

Commit 11bcf55

Browse files
committed
2348 solved.
1 parent 056f8f6 commit 11bcf55

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
cmake_minimum_required(VERSION 3.22)
2+
project(cpp_2348)
3+
4+
set(CMAKE_CXX_STANDARD 14)
5+
6+
add_executable(cpp_2348 main.cpp)
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/// Source : https://leetcode.com/problems/number-of-zero-filled-subarrays/
2+
/// Author : liuyubobobo
3+
/// Time : 2022-07-23
4+
5+
#include <iostream>
6+
#include <vector>
7+
8+
using namespace std;
9+
10+
11+
/// Split
12+
/// Time Complexity: O(n)
13+
/// Space Complexity: O(1)
14+
class Solution {
15+
public:
16+
long long zeroFilledSubarray(vector<int>& nums) {
17+
18+
int n = nums.size();
19+
long long res = 0;
20+
for(int start = 0, i = 1; i <= n; i ++)
21+
if(i == n || nums[i] != nums[start]){
22+
if(nums[start] == 0){
23+
long long len = i - start;
24+
res += (len + 1ll) * len / 2ll;
25+
}
26+
start = i;
27+
}
28+
return res;
29+
}
30+
};
31+
32+
33+
int main() {
34+
35+
return 0;
36+
}

readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2198,6 +2198,7 @@ email: [liuyubobobo@gmail.com](mailto:liuyubobobo@gmail.com)
21982198
| 2345 | [Finding the Number of Visible Mountains](https://leetcode.com/problems/finding-the-number-of-visible-mountains/) | [] | [C++](2001-2500/2345-Finding-the-Number-of-Visible-Mountains/cpp-2345/) | | |
21992199
| 2346 | Database Problem: [Link](https://github.com/liuyubobobo/Play-Leetcode-Database/) | - | - | - | - |
22002200
| 2347 | [Best Poker Hand](https://leetcode.com/problems/best-poker-hand/) | [] | [C++](2001-2500/2347-Best-Poker-Hand/cpp-2347/) | | |
2201+
| 2348 | [Number of Zero-Filled Subarrays](https://leetcode.com/problems/number-of-zero-filled-subarrays/) | [] | [C++](2001-2500/2348-Number-of-Zero-Filled-Subarrays/cpp-2348/) | | |
22012202
| | | | | | |
22022203

22032204
## 力扣中文站比赛

0 commit comments

Comments
 (0)