File tree Expand file tree Collapse file tree 3 files changed +43
-0
lines changed
2001-2500/2348-Number-of-Zero-Filled-Subarrays/cpp-2348 Expand file tree Collapse file tree 3 files changed +43
-0
lines changed Original file line number Diff line number Diff line change
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 )
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change @@ -2198,6 +2198,7 @@ email: [liuyubobobo@gmail.com](mailto:liuyubobobo@gmail.com)
2198
2198
| 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/ ) | | |
2199
2199
| 2346 | Database Problem: [ Link] ( https://github.com/liuyubobobo/Play-Leetcode-Database/ ) | - | - | - | - |
2200
2200
| 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/ ) | | |
2201
2202
| | | | | | |
2202
2203
2203
2204
## 力扣中文站比赛
You can’t perform that action at this time.
0 commit comments